You are on page 1of 5

Implementation of Caesar Cipher Substitution Technique

Aim:
To write a java program to implement the caesar cipher that gets the plain text
and generates the cipher text.

Algorithm:
1. Initialize the variable ALPHABET = abcd......xyz as a public static final
String.
2. Get the input plain text using Scanner class.
3. Call the method encrypt().
4. In encrypt() method do the following:
a) Get the plain text.
b) Convert it into lower case.
c) Shift Key = 3 [ every character of the message is replaced by its next 3rd
character ]
d) The key value is calculated by (Shift Key + Position of the character) %
26.
e) Replace each character in plain text based on the key value and store it
as cipher text.
5. Print the output cipher text.

Implementation of Playfair Cipher Substitution Technique

Aim:
To write a java program to implement the playfair cipher that gets the plain text
and generates the cipher text.

Algorithm:
1. Get the input plain text using Scanner class.
2. Get the keyword to encrypt the plain text.
3. The keyword is converted into key matrix by the following rules:
a) The matrix is constructed by filling in the letters of the keyword (minus
duplicates) from left to right and from top to bottom
b) then filling in the remainder of the matrix with the remaining letters in
alphabetic order.
c) The letters I and J count as one letter.
4. Plain text is encrypted two letters at a time, according to the following rules:
a) Repeating plain text letters that are in the same pair are separated with a
filler letter X.
b) Two plain text letters that fall in the same row of the matrix are each
replaced by the letter to the right, with the first element of the row
circularly following the last.
c) Two plain text letters that fall in the same column are each replaced by
the letter beneath, with the top element of the column circularly
following the last.
d) Otherwise, each plain text letter in a pair is replaced by the letter that
lies in its own row and the column occupied by the other plain text
letter.
5. Print the output encrypted text.
Implementation of Hill Cipher Substitution Technique

Aim:
To write a java program to implement the hill cipher that gets the plain text and
generates the encrypted text.

Algorithm:
1. Get the input plain text using Scanner class.
2. Get the block size of key matrix using Scanner class.
3. Create the object for class Hill.
4. The Hill class, get the Key Matrix from user.
5. Get the keyword to encrypt the plain text.
6. Remove all the blank spaces in the given sentence.
7. This encryption algorithm takes m successive plain text letters and
substitutes for them m cipher text letters. The substitution is determined by
m linear equations in which each character is assigned a numerical value
8. Plain text is encrypted two letters at a time, according to the following rules:
a) Repeating plain text letters that are in the same pair are separated with a
filler letter X.
b) Otherwise, encrypt the block using following formula:
C = P * K mod 26
Where,
C - row vector representing cipher text
P - row vector representing plain text
K - key value
9. Print the output encrypted text.

Implementation of Vigenere Cipher Substitution Technique

Aim:
To write a java program to implement the vigenere cipher that gets the plain text
and generates the cipher text.

Algorithm:
1. Get the input plain text using Scanner class.
2. Get the key text using Scanner class.
3. Encrypt the plain text by using key text as follows:
a) Change the letters in plain text to upper case.
b) For each character do the following
c) Encrypting alphabetic text by using a series of different Caesar ciphers
based on the letters of a keyword
d) Find resultant character by using following formula:
res += (char) ((c + key.charAt(j) - 2 * 'A') % 26 + 'A')
e) The value of j is incremented by ++j % key.length( ).
4. Print the output cipher text.
Implementation of Rail Fence Cipher Transposition Technique

Aim:
To write a java program to implement the rail fence cipher that gets the plain text
and generates the encrypted text.

Algorithm:
1. Get the input plain text using Scanner class.
2. Get the depth of the encryption using Scanner class.
3. Encrypt the plain text by using depth of encryption as follows:
a) Create the matrix which has the rows as depth of encryption and
columns as length of plain text / depth of encryption
b) The encryption is done by the matrix as follows:
i. For all positions, mat[j][i]=plainText.charAt(k++). Note that
initially k = 0.
ii. If the character is a last character, then it is encrypted as a filler text
X.
4. The encrypted text as nothing but mat[i][j].
5. Print the output encrypted text.

Implementation of DES Algorithm

Aim:
To write a java program to implement the DES algorithm that gets the plain text
and generates the encrypted text.

Algorithm:
1. Create the object for KeyGenerator class with the instance of DES.
2. Create the object for Cipher class with the instance of
"DES/CBC/PKCS5Padding"
3. Generate the key value using generateKey( ) method.
4. Get the input plain text using Scanner class.
5. Change the plain text into byte type value.
6. The encryption is done by calling of doFinal( ) method.
7. Print the output encrypted text.

Implementation of RSA Algorithm

Aim:
To write a java program to implement the RSA algorithm that gets the plain text
and generates the encrypted text.

Algorithm:
1. Initialize bitlength = 1024.
2. The constructor of RSA class has following constructions:
i. r as random value.
ii. p and q are probable prime values.
iii. N = p * q
iv. Phi and e are probable prime values.
v. d = e.modInverse(phi)
3. Get the input plain text using Scanner class.
4. Convert the plain text into byte stream.
5. The encryption of plain text is done by following:
new BigInteger(message).modPow(e, N).toByteArray( )
6. Print the output encrypted text.

Implementation of Diffie Hellman Key Exchange Algorithm

Aim:
To write a java program to implement the Diffie Hellman key exchange
algorithm.

Algorithm:
1. Get a start spot to pick a prime from the user.
2. Get the base for exponentiation from the user.
3. Get A's secret number.
4. Make A's calculation. This is the value that will get sent from A to B.
modPow(As secret number, prime number)
5. Get B's secret number.
6. Make B's calculation. This is the value that will get sent from B to A.
modPow(Bs secret number, prime number)
7. Once A and B receive their values, they make their new calculations. This
involved getting their new numbers and raising them to the same power as
before, their secret number.
8. Print out the Key A calculates.
9. Print out the Key B calculates.

Implementation of MD5 Message Digest Algorithm

Aim:
To write a java program to implement the MD5 message digest algorithm.

Algorithm:
1. Create the string array which has a test strings.
2. For each string do the following:
3. Convert the string into bytes.
4. Compute the MD5 by using byte stream of input string.
5. Let us assume the output as string of length 16.
6. The MD5 value is computed in length 16.
7. This Digest Message is converted into hexadecimal value of length 16.
8. Print the hexadecimal value for each string in the test strings array.
Implementation of SHA-1 Algorithm

Aim:
To write a java program to implement the SHA-1 algorithm.

Algorithm:
1. Get the input text to test the SHA-1 algorithm.
2. Create the object for the class MessageDigest with the instance of SHA1
3. Digest the bytes of input string using the method digest( ).
4. The digested integer value is converted into string by following :
Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)
Where result[i] is the digested integer value.
5. Print the output string.

Implementation of Digital Signature Scheme

Aim:
To write a java program to implement the digital signature scheme.

Algorithm:
1. Create the object kpg for KeyPairGenerator class with instance of RSA.
2. Initialize kpg is 1024 bit data.
3. Create the object for KeyPair class.
4. Get the message to send by the sender.
5. Convert the message into UTF8 form bytes.
6. Create the digital signature with instance of MD5WithRSA
7. The signature is encoded with input message and that is send to receiver.
8. The receiver generates the public key of sender.
9. The signature is validated in receiver side.
10. The validity of signature is printed as output of the program.