proj home

Files   Classes   Functions   Hierarchy  

passwordverifier001.cpp

Go to the documentation of this file.
00001 #include <sstream>
00002 using namespace std;
00003 
00004 #include <passwordverifier001.h>
00005 #include <print.h>
00006 
00007 
00008 void passwordverifier001::eval( ZZ & val ) const
00009 {
00010   // The password must be less than n1
00011   // to go into the PowerMod funtion.
00012   // Further having it greater than n1
00013   // is meaningless.
00014   assert(password < n1);
00015 
00016 //cout << SHOW(password) << endl;
00017 //cout << SHOW(j1) << endl;
00018 //cout << SHOW(n1) <<endl;
00019   ZZ w;
00020   PowerMod(w,password%n1,j1,n1);
00021 //cout << SHOW(w) << endl;
00022   w += k1;
00023 //cout << SHOW(w) << endl;
00024   PowerMod(val,w%n2,j2,n2);
00025 }
00026 
00027 void passwordverifier001::eval( string & val ) const
00028 {
00029   ZZ w;
00030   eval(w);
00031 
00032   stringstream ss;
00033   ss << w;
00034   val = ss.str();
00035 }
00036   
00037 boolc passwordverifier001::verify
00038 ( 
00039   stringc & attempt 
00040 ) const
00041 {
00042   string val;
00043   eval(val);
00044   
00045   return (attempt == val);
00046 }
00047 
00048 void passwordverifier001::parameters_get
00049 (
00050   string & parameters 
00051 )
00052 {
00053   parameters = "";
00054 
00055   string str;
00056   convInverse(str,j1);
00057   parameters += (str + " ");
00058   convInverse(str,j2);
00059   parameters += (str + " ");
00060   convInverse(str,n1);
00061   parameters += (str + " ");
00062   convInverse(str,n2);
00063   parameters += (str + " ");
00064   convInverse(str,k1);
00065   parameters += str;
00066 }
00067 
00068 void passwordverifier001::convInverse
00069 (
00070   string & wstr, 
00071   ZZ const w 
00072 )
00073 {
00074   stringstream ss;
00075   ss << w;
00076   wstr = ss.str();
00077 }
00078 
00079 void passwordverifier001::parameters_set
00080 (
00081   stringc & parameters 
00082 )
00083 {
00084   stringstream ss(parameters);
00085   string str;
00086 
00087   ss >> str;
00088   conv(j1,str.c_str());
00089 
00090   ss >> str;
00091   conv(j2,str.c_str());
00092 
00093   ss >> str;
00094   conv(n1,str.c_str());
00095 
00096   ss >> str;
00097   conv(n2,str.c_str());
00098 
00099   ss >> str;
00100   conv(k1,str.c_str());
00101 }
00102 
00103 void passwordverifier001::random(ZZ & num, uintc nb)
00104 {
00105   RandomBits(num,nb);
00106   ZZ n2;
00107   ZZ x;
00108   conv(x,"2"); 
00109   power(n2,x,nb);
00110   if (num<n2)
00111     num += n2;
00112 }
00113 
00114 void passwordverifier001::generatePassword()
00115 {
00116   random(password,nbits-1);
00117 }
00118 
00119 void passwordverifier001::generateRandomFunction()
00120 {
00121   random(j1,nbits);
00122   random(j2,nbits);
00123   random(n1,nbits);
00124   random(n2,nbits);
00125   random(k1,nbits);
00126 }
00127 

Generated on Fri Mar 4 00:49:31 2011 for Chelton Evans Source by  doxygen 1.5.8