123 Eng

### Engineering the engineers™

Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

Computer Science / IT
Electronics
Electrical
Mechanical
Chemical
Civil

CAT / MBA

GMAT / Foreign MBA
Latest Jobs

Displaying  Source Code(s)

 RSA Algorithm (Mini Project) -------------------------------------------------------------------------------- Description : It encrypts not only the numbers, also the text message you will give. Code : //Header File--RSA Application //Miller & Rabin Algorithm--Test for Primality //PseudoRandom Number Generator Algorithm //Relatively Prime--Euclid's Algorithm #include #include #include #include #include #include #include class RSA { public: int pr1,pr2,x1,n,n1; int e,d,pt; int a[20],b[10]; int len; //binary array length RSA(); //Miller & Rabin Algorithm--Test for Primality void testprimality(); //PseudoRandom Number Generator Algorithm void pseudo1(); int pseudo2(); //Relatively Prime--Euclid's Algorithm //GCD of two numbers-their common factor is '1' void relprime(); int gcd(int c,int d); //Key Generation int keygenerate1(int ptext);//for Encryption int keygenerate2(int ctext);//for Decryption void decitobin(int x); //Encryption int encrypt(int num); //Decryption int decrypt(int ctext); }; //Interface File--RSA Application //Miller & Rabin Algorithm--Test for Primality //PseudoRandom Number Generator Algorithm //Relatively Prime--Euclid's Algorithm #include"rh1.h" RSA::RSA() { x1=1; pr1=0; pr2=0; } //Miller & Rabin Algorithm--Test for Primality void RSA::testprimality() { int a,j,p1,q,x; int t1,t2; int k,flag,ch; ch=1; flag=0; k=0; //(n-1)=pow(2,k)*q //divide (n-1) by 2 until result is odd number while(ch) { x=(n-1)/(int)(pow(2,k)); if(fmod(x,2)==1) { ch=0; break; } k++; } q=(int)((n-1)/(pow(2,k))); //to pick an integer randomly which //should be less than 'n'; //That's why calling pseudo2() a=pseudo2(); if(a>1 && a<(n-1)) { t1=(int)(pow(a,q)); if((t1%n)==1) flag=1; else { for(j=0;j<=(k-1);j++) { p1=((int)(pow(2,j)))*q; t2=(int)pow(a,p1); if((t2%n)==(n-1)) flag=1; } } } if(flag==1) if(pr1==0) pr1=n; else if(pr1!=0 && pr2==0) pr2=n; } //PseudoRandom Number Generator Algorithm void RSA::pseudo1() { //to select 'n' pseudorandomly and pass to testprimality(); //'n' is to be proved either prime or not prime int a,c,y; unsigned int m; y=0; a=(int)pow(7,5); //(7,2),*(7,4),(7,5) //(int)pow(7,5) used in IBM 360 //m should be assigned a "prime" no. //up to pow(2,31) should be used. //(2,5)-1;(2,7)-1;(2,13)-1; //(2,17)-1;(2,19)-1;(2,31)-1 are primes m=((int)pow(2,7))-1; //(2,7) n=1;c=0; for(int i=0;i<50;i++) { n=((a*n)+c)%m; testprimality(); //n will be computed in textprimality() } // cout<<" pr1 = "<array contains binary value of 'e' for(i=len;i>=0;i--) { c=2*c; entext=(entext*entext)%n1; //187->n1 if(a[i]==1) { c=c+1; entext=(entext*ptext)%n1; //187->n1 } } // cout<<" Encrypted 'c' : "<array contains binary value of 'd' for(i=len;i>=0;i--) { c=2*c; dntext=(dntext*dntext)%n1; if(a[i]==1) { c=c+1; dntext=(dntext*ctext)%n1; } } // cout<<" Decrypted 'c' := "<0) { a[i]=x%2; i++; x=x/2; } //when exit from above loop, i value is incremented by 1 k=i-1; len=i-1; } int RSA::encrypt(int num) { int ctext,i; pt=num; ctext=keygenerate1(num); return(ctext); } int RSA::decrypt(int ctext) { int dectext,i; dectext=keygenerate2(ctext); return(dectext); } //Application File--RSA Application //Miller & Rabin Algorithm--Test for Primality //PseudoRandom Number Generator Algorithm //Relatively Prime--Euclid's Algorithm #include"rh1.h" #include void main() { int i,det,det1,len,k,k1,cnt; int con=0,c; char ch[100],cipher[20],orig[20]; RSA r; c=1; cout<; for(i=0;i<70;i++) cout<<'*'; cout<

Contribute content or training reports / feedback / Comments
job placement papers