/* * Program to decode message using RSA private key. * * Requires: big.cpp crt.cpp */ #include #include #include #include "big.h" /* include MIRACL system */ #include "crt.h" /* chinese remainder thereom */ using namespace std; #define NP 2 /* two primes - could be used with more */ Miracl precision=100; void strip(char *name) { /* strip extension off filename */ int i; for (i=0;name[i]!='\0';i++) { if (name[i]!='.') continue; name[i]='\0'; break; } } int main() { /* decode using private key */ int i; Big e,ep[NP],m,ke,p[NP],kp[NP],mn,mx; ifstream private_key("private.key"); ifstream input_file; ofstream output_file; char ifname[13],ofname[13]; BOOL flo; miracl *mip=&precision; mip->IOBASE=16; for (i=0;i> p[i]; } /* construct public and private keys */ ke=1; for (i=0;iIOBASE=16; input_file >> m; if (m==0) break; for (i=0;i=mx) e%=mn; mip->IOBASE=128; if (flo) output_file << e; cout << e << flush; } cout << "message ends\n"; return 0; }