PLAYFAIR CIPHER
ENCRYPTION
1. Input: Receive the plaintext and the keyword.
2. Key Matrix Generation:
Create a 5x5 matrix (usually a grid) using the keyword, removing duplicate letters
and filling in the remaining spaces with the alphabet.
3. Text Preprocessing:
Remove any spaces and punctuation from the plaintext.
Handle any special cases like double letters by inserting a filler letter (usually 'X')
between them.
4. Letter Pair Generation:
Split the plaintext into letter pairs.
If the last letter is unmatched (an odd number of letters), append a filler letter
(usually 'X').
5. Encryption:
For each letter pair:
Determine the positions of the letters in the key matrix.
Apply the following rules:
If both letters are in the same row, replace each letter with the
letter to its right (wrapping around if necessary).
If both letters are in the same column, replace each letter with the
letter below it (wrapping around if necessary).
If the letters form a rectangle, replace each letter with the letter in
the same row but in the column of the other letter.
If the letters are in different rows and columns, form a rectangle and
replace each letter with the letter in the same row but in the column
of the other letter.
6. Output: The encrypted ciphertext.
DECRYPTION
1. Input: Receive the ciphertext and the keyword.
2. Key Matrix Generation:
Create a 5x5 matrix (usually a grid) using the keyword, removing duplicate letters
and filling in the remaining spaces with the alphabet.
3. Decryption:
For each letter pair in the ciphertext:
Determine the positions of the letters in the key matrix.
Apply the following rules to decrypt:
If both letters are in the same row, replace each letter with the
letter to its left (wrapping around if necessary).
If both letters are in the same column, replace each letter with the
letter above it (wrapping around if necessary).
If the letters form a rectangle, replace each letter with the letter in
the same row but in the column of the other letter.
If the letters are in different rows and columns, form a rectangle and
replace each letter with the letter in the same row but in the column
of the other letter.
4. Text Postprocessing:
Remove any filler letters (usually 'X').
Combine the decrypted letter pairs into the plaintext.
5. Output: The decrypted plaintext.
**********************************************************************************
COLUMN TRANSPOSITION CIPHER
ENCRYPTION
1. Input: Receive the plaintext and the columnar permutation key.
2. Text Preprocessing:
Remove any spaces and punctuation from the plaintext.
Determine the number of rows required for the grid based on the length of the
plaintext and the key.
3. Grid Formation:
Write the plaintext into a grid row by row, filling each row left to right.
If necessary, pad the last row with filler characters to complete the grid.
4. Column Permutation:
Rearrange the columns of the grid according to the permutation key.
5. Output: The encrypted ciphertext, read column by column.
DECRYPTION
1. Input: Receive the ciphertext and the columnar permutation key.
2. Grid Formation:
Determine the number of columns based on the length of the ciphertext and the
key.
Write the ciphertext into a grid column by column, filling each column top to
bottom.
3. Column Permutation Reversal:
Rearrange the columns of the grid to their original order based on the permutation
key.
4. Output: The decrypted plaintext, read row by row.
**********************************************************************************
**********************************************************************************
RAIL FENCE CIPHER
ENCRYPTION
1. Input: Receive the plaintext and the number of rails (depth).
2. Text Preprocessing:
Remove any spaces and punctuation from the plaintext.
3. Rail Fence Formation:
Write the plaintext diagonally across a number of "rails" (rows) equal to the depth,
zigzagging up and down.
Fill in the remaining spaces with placeholder characters if necessary.
4. Output: The encrypted ciphertext, read row by row.
DECRYPTION
1. Input: Receive the ciphertext and the number of rails (depth).
2. Rail Fence Reconstruction:
Create an empty grid with the same number of rows and columns as the rail fence
used for encryption.
Fill in the ciphertext diagonally across the grid, following the zigzag pattern.
3. Text Extraction:
Read the grid row by row to extract the plaintext.
4. Output: The decrypted plaintext.
**********************************************************************************
ADDITIVE CIPHER
Encryption:
1. Input: Receive the plaintext and the shift key.
2. Text Preprocessing:
Remove any spaces and punctuation from the plaintext.
3. Encryption:
Shift each letter in the plaintext forward by the value of the shift key (adding the key
to the ASCII value of each character).
4. Output: The encrypted ciphertext.
Decryption:
1. Input: Receive the ciphertext and the shift key.
2. Decryption:
Shift each letter in the ciphertext backward by the value of the shift key (subtracting
the key from the ASCII value of each character).
3. Output: The decrypted plaintext.
__________________________________________________________________________________
Please explore the online resources as well for a better understanding.
All the Best for your 2nd code-based test.