Posts

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 MD5 ALGORITHM using Java

Image
AIM: To write a program in java to   calculate the message digest of a text using the MD-5. ALGORITHM: Step1: Append padding bits to the input plain text Step2: Append length Step3: Initialize MD buffer Step4: Process message in 512-bit(16word)blocks Step5: Display the hashed text. PROGRAM: import java.io.FileInputStream; import java.io.UnsupportedEncodingException; importjava.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MD5 {     public static String getMD5(String input) {         try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input.getBytes()); BigInteger number = new BigInteger(1, messageDigest);             String hashtext = number.toString(16);        ...

IMPLEMENTATION OF DIFFIE HELLMAN KEY EXCHANGE ALGORITHM

Image
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; ...

IMPLEMENTATION OF RSA ALGORITHM using c++

AIM: To write a   C++ program   to implement 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 =   m e mod n , Step 8: Decryption: m = c d mod 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; intf...

IMPLEMENTATION OF DES using java

AIM: Towrite a program   to implement DES   encryption and decryption in java. ALGORITHM: Step 1: Enter the plain text and key Step 2: Initial permutation (IP) will be done for the plain text and key. Step 3: 16 rounds of a complex key dependent calculation f Function f   is L(i) = R(i-1) R(i) = L(i-1) Å P(S( E(R(i-1)) Å K(i) )) Step 4: A final permutation, being the inverse of IP will be done to get cipher text. Step 5:   The above steps   4, 3, 2 are repeated in reverse order to get decrypted text. PROGRAM: import java.util.*; importjava.io.BufferedReader; importjava.io.InputStreamReader; importjava.security.spec.KeySpec; importjavax.crypto.Cipher; importjavax.crypto.SecretKey; importjavax.crypto.SecretKeyFactory; importjavax.crypto.spec.DESedeKeySpec; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; public class DES { private static final String UNICODE_FORMAT = "...

IMPLEMENTATION OF RAIL FENCE

Image
AIM:             To write a   C++ program   to Implement Rail fence row & column transformation. ALGORITHM: Step 1:   Enter the plain text for encryption. Step 2:   Enter the depth in integer (number of rows) Step 3: In the rail fence cipher, the  plaintext  is written downwards and diagonally on successive "rails" of an imaginary fence, then moving up when we reach the bottom rail. Step 4: When we reach the top rail, the message is written downwards again until the whole plaintext is written out. Step 5: The message is then read off in rows. Thus, the cipher text is generated. PROGRAM: #include<iostream> using namespace std; int main() { inti,j=0,d,k=0; char p[50],ct[50][50]; cout<<"Enter the plain text:\n"; cin>>p; cout<<"\nEnter the depth in the integer:"; cin>>d;     ...

IMPLEMENTATION OF VIGENERE CIPHER using C++

Image
AIM:             Towrite a   C++ program to implement Vigenere   Cipher. ALGORITHM: Step 1: Enter the plain text   for encryption. Step 2: Enter   the   encryption key pharse. Step 3:   Cipher text is obtained by modular addition   of a   key pharse and   plain   text. Step 4: For decryption to get the plaintext again the key pharse is modularly subtracted from the cipher   text. Step 5: Display the cipher text and plaintext. PROGRAM: // Vigenere Cipher #include <iostream> #include <string> using namespace std; class Vigenere {     public:         string key; Vigenere(string key)         { for (int i = 0; i <key.size(); ++i)             {  ...