IMPLEMENTATION OF SHA-1 ALGORITHM using JAVA

Image
AIM: To   write a java program to calculate the message digest of a text using the SHA-1 algorithm ALGORITHM: Step 1: Input the plain text Step 2: Append padding bits Step 3: Append length Step 4:Initialize   buffer. Step 5: Process message in 512-bit (16word)blocks Step 6: Encrypted in hexa decimal format Step 7: Display the encrypted text. PROGRAM: importjava.security.*; public class SHA1 { public static void main(String[] a) { try { MessageDigest md = MessageDigest.getInstance("SHA1"); System.out.println("Message digest object info: "); System.out.println(" Algorithm = " +md.getAlgorithm()); System.out.println(" Provider = " +md.getProvider()); System.out.println(" ToString = " +md.toString());   String input = ""; md.update(input.getBytes()); byte[] output = md.digest(); System.out.println(); System.out.println("SHA1(\""+...

IMPLEMENTATION OF RSA ALGORITHM using c++


AIM:

To write a  C++ program  toimplement encryption and decryption using RSA  Algorithm.



ALGORITHM:

Key generation:



Step 1: Select random prime numbers p and q , and check that p != q

Step 2: Compute modulus n = pq

Step 3: Compute phi, ¢ = (p - 1)(q - 1)

Step 4: Select public exponent e , 1 < e < ¢ . such that gcd(e, ¢ ) = 1

Step 5: Compute private exponent d =e-1 mod ¢

Step 6: Public key is {n, e}, private key is d

Encryption & Decryption

Step 7: Encryption: c =  memod n ,

Step 8: Decryption: m = cdmod n

Step 9: Display the cipher text and plain text.





PROGRAM:

//  RSA - Algortihm

#include<iostream>

using namespace std;

int main( )

{

inti,j,k,p,q,flag,e,x,d;

cout<<"\n RSA  ALGORITHM \n\n\n ";

cout<<" \n Enter Value of p :: ";

cin>>p;

cout<<" \n Enter Value of q :: ";

cin>>q;

int  n=p*q;

intfn=(p-1)*(q-1);

cout<<"\n Value of (p,q) :: "<<p<<" "<<q;

cout<<"\n Value of n,fn  :: "<<n<<" "<<fn;

cout<<"\n\n Select Public Key e (1 < e<"<<fn<<")";

cin>>e;

intsk;

for(i=1;i>0;i++)

  {

    x=i*e;

    d=x%fn;

    if(d==1)

    {

cout<<"\n\n Private Key ::"<< i;

sk = i;

    break;

    }

}





int pt;

cout<<"\n\n  Enter Plain Text ::";

cin>>pt;

int m=1;

for(i=0;i<e;i++)

      m=(m*pt)%n;

  m=m%n;

cout<<"\n\n  Cipher Text :: "<<m;

 k=1;

for(i=0;i<sk;i++)

      k=(k*m)%n;

  k=k%n;

cout<<"\n\n  Decrypted Text :: "<<k;

  return 0;

}

Comments

Popular posts from this blog

IMPLEMENTATION OF SHA-1 ALGORITHM using JAVA

IMPLEMENTATION OF DIFFIE HELLMAN KEY EXCHANGE ALGORITHM