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 DIFFIE HELLMAN KEY EXCHANGE ALGORITHM


AIM:

To write a  C++ program  to implement  Diffie Hellman key exchange algorithm.

ALGORITHM:

Step 1: Enter the value of n and g, both are prime numbers.

Step 2:Enter x and y and these are private chosen by the users alice and bob respectively.

Step 3: Alice calculates g x mod n and Bob calculates g y mod n

Step 4:Bob sends the value g y mod n to Alice and alice sends the value g x mod n to Bob.

Step 5: Alice will calculate the shared secret by (g y mod n )x mod n  and bob

b(g x mod n )y mod n.

Step 6: Display the shared secret key.

PROGRAM:

// Diffie Hellman key Exchange

#include<iostream>

using namespace std;

#include<math.h>

intalice(int,double,double);

int bob(int,double,double);

int main( )

{   longint a,b,k1,k2,n;

doubleg,x,y;

cout<<"\n  DIFFIE HELLMAN KEY EXCHANGE";

cout<<"\n\n\t Enter value of n & g";

cin>>n>>g;

cout<<"\n\n\t Enter value of x & y";

cin>>x>>y;

a=alice(n,g,x);

cout<<"\n\t alice end value:"<<a;

b=bob(n,g,y);

cout<<"\n\t bob end value:"<<b;

k1=alice(n,b,x);

cout<<"\n\t value of k1 :"<<k1;

k2=bob(n,a,y);

cout<<"\n\t value of k2 :"<<k2;

}

intalice(int n,  double  g,   double x)

{

long int   a;

double a1;

a1=pow(g,x);

a=(int)a1%n;

return(a);

}



OUTPUT:

Comments

Popular posts from this blog

IMPLEMENTATION OF SHA-1 ALGORITHM using JAVA

IMPLEMENTATION OF RSA ALGORITHM using c++