Experiment - 1
Aim: To Implement encryption and decryption using Rail Fence Cipher technique.
Algorithm Overview:
The Rail Fence Cipher is a form of transposition cipher that encrypts text by arranging it in a
zigzag pattern across multiple "rails" or lines. Here's how to implement encryption and
decryption using the Rail Fence Cipher technique.
·
1.
2.
3.
Encryption
Input the plain-text and the number of rails.
Create a grid based on the number of rails, filling it in a zigzag pattern.
Read off the characters row by row to create the cipher-text.
·
1.
2.
3.
Decryption
Input the cipher-text and the number of rails.
Reconstruct the grid using the length of the cipher-text.
Fill in the grid in a zigzag pattern, then read the plain-text row by row.
Implementation:
Example Usage:
·
·
Input: "HELLO RAIL FENCE CIPHER" with 3 rails.
Output: Prints the encrypted text and then the decrypted text back to the original.
Experiment 2
Aim: To implement the Data Encryption Standard (DES) algorithm in Java for encrypting and
decrypting a message.
Algorithm Overview:
DES is a symmetric-key algorithm for the encryption of digital data. It operates on blocks of
data, typically 64 bits, and uses a 56-bit key.
1. Input:
– A 64-bit block of plain-text.
– A 56-bit key (the original key is 64 bits, but only 56 bits are used after dropping 8
parity bits).
2. Initial Permutation (IP):
– Apply the initial permutation on the 64-bit plain-text.
3. Splitting:
– Divide the permuted block into two 32-bit halves: Left and Right.
4. Rounds:
– Perform 16 rounds of processing, where each round involves:
Expansion (expanding the 32-bit right half to 48 bits).
XOR with the round key (each round uses a different 48-bit subkey
derived from the main key).
Substitution (using 8 S-boxes to reduce the 48-bit result to 32 bits).
Permutation (permuting the bits).
Swapping halves for the next round.
5. Final Permutation (FP):
– After 16 rounds, combine the halves and apply the final permutation.
6. Decryption:
– The process is reversed using the same keys, but in reverse order.
Implementation:
Example Usage:
·
·
Input: "Galgotias University III YEAR CSE" with the secret key.
Output: Prints the encrypted text and then the decrypted text back to the original.
Experiment 3
Aim: To implement the Advanced Encryption Standard (AES) algorithm in Java for
encrypting and decrypting a message.
Algorithm Overview:
AES is a symmetric encryption algorithm that can handle encryption of blocks of data of 128 bits
using keys of 128, 192, or 256 bits.
1. Input:
– A 128-bit block of plain-text.
– A key size of either 128, 192, or 256 bits.
2. Key Expansion:
– The AES key is expanded into an array of round keys, using the Rijndael key
schedule.
3. Initial Round:
– AddRoundKey: Each byte of the state is combined with a block of the round key
using a bitwise XOR operation.
4. Rounds (Number of rounds is 10, 12, or 14 depending on the key size):
– SubBytes: Non-linear substitution step where each byte is replaced with another
according to a lookup table (S-box).
– ShiftRows: A transposition step where the last three rows of the state are shifted
cyclically by different offsets.
– MixColumns: Mixing operation which operates on the columns of the state,
combining the four bytes in each column.
– AddRoundKey: Each byte of the state is combined with a part of the round key
using XOR.
5. Final Round:
– SubBytes, ShiftRows, and AddRoundKey (without MixColumns).
6. Decryption:
– AES decryption is done by reversing all the steps in the encryption process, using
the same key.
Implementation:
Example Usage:
·
·
Input: "Galgotias University III YEAR CSE" with the secret key.
Output: Prints the encrypted text and then the decrypted text back to the original.
Experiment 4
Aim: To implement the RSA algorithm in Java for encryption and decryption of
messages.
Algorithm Overview:
The RSA (Rivest–Shamir–Adleman) algorithm is a public-key cryptosystem that is widely used
for secure data transmission. It is based on the difficulty of factoring the product of two large
prime numbers.
1. Key Generation:
– Select two large prime numbers p and q.
– Compute n = p * q.
– Compute Euler’s Quotient function, φ(n) = (p - 1) * (q - 1).
– Select an integer e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1. e is the public key
exponent.
– Compute d such that d * e ≡ 1 (mod φ(n)). d is the private key exponent.
2. Encryption:
– cipher-text, C = (M^e) mod n, where M is the plain-text (message) and e is the
public key exponent.
3. Decryption:
– plain-text, M = (C^d) mod n, where C is the cipher-text and d is the private key
exponent.
Implementation:
Example Usage:
·
·
Input: "123456" with the secret key.
Output: Prints the encrypted text and then the decrypted text back to the original.
Experiment 5
Aim: To implement the Diffie-Hellman Key Exchange Algorithm in Java for securely
exchanging cryptographic keys over a public channel.
Algorithm Overview:
Diffie-Hellman is a method used to generate a shared secret between two parties, which can then
be used to encrypt and decrypt messages using symmetric encryption algorithms.
1. Initialization:
– Two parties (Alice and Bob) agree on two large prime numbers: p (a prime
modulus) and g (a generator, which is a primitive root modulo p).
– These numbers p and g can be made public.
2. Private Key:
– Each party selects a private key:
Alice selects a private key a.
Bob selects a private key b.
3. Public Key Generation:
– Each party computes their public key using the following formula:
Alice computes A = g^a mod p.
Bob computes B = g^b mod p.
Both A and B are exchanged publicly.
4. Shared Secret:
– Both parties can compute the same shared secret using the following:
Alice computes S = B^a mod p.
Bob computes S = A^b mod p.
The shared secret S will be the same for both Alice and Bob, even though
they exchanged only public information.
5. Symmetric Key Encryption:
– This shared secret can be used as a key for symmetric encryption (like AES) to
encrypt and decrypt messages securely.
Implementation:
Example Usage:
·
·
Input: Message to encrypt: "Galgotias University"
Output:
a. Shared Secret (Alice): k8iFD+afj0GtqfF9k4v5R1FjQ4TdI7I5Bkk8e8E0BY4=
b. Shared Secret (Bob): k8iFD+afj0GtqfF9k4v5R1FjQ4TdI7I5Bkk8e8E0BY4=
c. Encrypted Message: q1FjR8MR8e84n3oN4FfEow==
d. Decrypted Message: Galgotias University