proj home

Files   Classes   Functions   Hierarchy  

rsatest Class Reference

RSA tests for all rsa and associated classes. More...

#include <rsatest.h>

List of all members.

Static Public Member Functions

static int unittest01 ()
 Small RSA example with maths library.
static int unittest02 ()
 Small RSA example with rsa classes.
static void test01 ()
 String and stream conversions written to files.
static void test02 (int argc, char **argv)
 Comparing sequential and random prime generation.


Detailed Description

RSA tests for all rsa and associated classes.

Definition at line 7 of file rsatest.h.


Member Function Documentation

void rsatest::test01 (  )  [static]

String and stream conversions written to files.

Definition at line 84 of file rsatest.cpp.

References digdiv::blksz, digdiv::forward(), asciitodig::forward(), digdiv::reverse(), and asciitodig::reverse().

Referenced by main().

00085 {
00086   string s;
00087   ifstream f1("main.cpp");
00088   asciitodig::forward(s,f1);
00089   ofstream f2("tmp11.txt");
00090   asciitodig::reverse(f2,s);
00091 
00092   digdiv d;
00093   d.blksz = 5;
00094   d.forward(s);
00095 //  printv(d.v);
00096   ofstream f3("tmp12.txt");
00097   string s2;
00098   d.reverse(s2);
00099   asciitodig::reverse(f3,s2);
00100 }

void rsatest::test02 ( int  argc,
char **  argv 
) [static]

Comparing sequential and random prime generation.

Definition at line 102 of file rsatest.cpp.

References aclock::diff_s(), largePrimeGenerator::findprime_randomly(), largePrimeGenerator::findprime_sequentially(), commandline::mapvar(), and aclock::measure().

Referenced by main().

00103 {
00104   commandline c(argc,argv);
00105   unsigned int nbits(200);
00106   c.mapvar(nbits,"nbits");
00107 
00108   largePrimeGenerator p;
00109 
00110   aclock clk;
00111   clk.measure();
00112   ZZ n;
00113   unsigned int imax=30;
00114   for ( unsigned int i=0; i<imax; ++i )
00115   {
00116     p.findprime_sequentially(n,nbits);
00117     cout << n << endl;
00118   }
00119   clk.measure();
00120   cout << "sequential time(s)=" << clk.diff_s() << endl;
00121 
00122   for ( unsigned int i=0; i<imax; ++i )
00123   {
00124     p.findprime_randomly(n,nbits);
00125     cout << n << endl;
00126   }
00127   clk.measure();
00128   cout << "random time(s)=" << clk.diff_s() << endl;
00129 }

int rsatest::unittest01 (  )  [static]

Small RSA example with maths library.

Definition at line 18 of file rsatest.cpp.

Referenced by main().

00019 {
00020   cout << "Small RSA example with maths library." << endl;
00021 
00022   ZZ p;
00023   conv(p,"47");
00024   ZZ q;
00025   conv(q,"71");
00026   ZZ n = p*q;
00027   ZZ n2 = (p-1)*(q-1);
00028 
00029   ZZ e;
00030   conv(e,"79");
00031  
00032   ZZ d;
00033   InvMod(d,e,n2);
00034 
00035   cout << "d=" << d << endl;
00036 
00037   ZZ m;
00038   conv(m,"688");
00039   cout << "m=" << m << endl;
00040 
00041   ZZ c;
00042   PowerMod(c,m,e,n);
00043   cout << "c=" << c << endl;
00044 
00045   ZZ m2;
00046   PowerMod(m2,c,d,n);
00047   cout << "D(c)=" << m2 << endl;
00048 
00049   if (m!=m2)
00050     return 1;
00051 
00052   return 0;
00053 }

int rsatest::unittest02 (  )  [static]

Small RSA example with rsa classes.

Definition at line 55 of file rsatest.cpp.

References rsaD::e, rsaE::e, rsaD::init(), rsaE::n, rsaD::p, and rsaD::q.

Referenced by main().

00056 {
00057   cout << "Small RSA example with rsa classes." << endl;
00058   rsaE E;
00059   conv(E.e,"79");
00060   conv(E.n,"3337");  //47*71=3337
00061 
00062   string m1("688");
00063   string c1;
00064   E(c1,m1);
00065   cout << "c1=" << c1 << endl;
00066 
00067   rsaD D;
00068   conv(D.e,"79");
00069   conv(D.p,"47");
00070   conv(D.q,"71");
00071   D.init();
00072 
00073 
00074   string m2;
00075   D(m2,c1);
00076   cout << "m2=" << m2 << endl;
00077 
00078   if (m1!=m2)
00079     return 1;
00080 
00081   return 0;
00082 }


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:16 2011 for Chelton Evans Source by  doxygen 1.5.8