Pseudocode Encryptiopn
Pseudocode Encryptiopn
Variables:
• Plaintext: The message to be encrypted or decrypted. Example: "HELLO".
• Key: A keyword or string used to generate a 5x5 key matrix. Example:
"MONARCHY".
• Key Matrix: A 5x5 grid containing the letters of the alphabet (excluding 'J'). This is
generated using the key and filled with remaining letters. Example:
MONAR
CHYBD
EFGIK
LPQST
UVWXZ
• Letter Pairs: The plaintext is divided into pairs of letters (e.g., "HE", "LX" for
"HELLO", with "X" inserted).
• Ciphertext: The encrypted message after applying the Playfair substitution rules.
Example: "CFIKNP".
Flow Chart Steps:
1. Start.
2. Input the plaintext and key.
3. Create the 5x5 key matrix using the key.
4. Prepare the plaintext:
o Remove repeated letters in pairs (insert 'X' if needed).
o Make pairs of two letters.
5. For each pair of letters in the plaintext:
o If the letters are in the same row, replace each with the letter to its right.
o If the letters are in the same column, replace each with the letter below.
o If the letters form a rectangle, replace each with the letter on the opposite corner.
6. Combine the modified letter pairs into the final ciphertext or plaintext.
7. Output the ciphertext or plaintext.
8. End.
Pseudo Code:
Input: plaintext, key
Output: ciphertext
1. Start
2. Create 5x5 key matrix from key (remove repeated letters and exclude 'J')
3. Preprocess plaintext:
a. Remove repeated letters in pairs, insert 'X' between them if needed
b. Split plaintext into letter pairs
4. For each pair of letters:
a. Find the positions of both letters in the key matrix
b. If both letters are in the same row, replace with the letters to their right
c. If both letters are in the same column, replace with the letters below
d. If letters form a rectangle, replace with letters on the opposite corners
5. Combine all pairs to form ciphertext
6. Return ciphertext
7. End
1. Start
2. Agree on a large prime number p and base g.
3. Alice selects a private key a, Bob selects a private key b.
4. Alice computes her public key A = g^a mod p.
5. Bob computes his public key B = g^b mod p.
6. Exchange public keys:
a. Alice sends A to Bob, Bob sends B to Alice.
7. Both compute the shared secret key:
a. Alice computes K = B^a mod p.
b. Bob computes K = A^b mod p.
8. Both parties now share the same secret key K.
9. End
Hill Cipher
Variables:
● Plaintext: The original message to be encrypted or decrypted, usually converted to
numeric form (A=0, B=1, ..., Z=25).
● Key Matrix: A square matrix used for encryption. The size of the matrix is based on
the length of the block (e.g., 2x2 or 3x3), and the matrix contains integer values.
● Block Size: The size of the block (number of characters) that the matrix operates on.
For example, a 2x2 key matrix works on pairs of letters, and a 3x3 matrix works on
triplets of letters.
● Ciphertext: The result of multiplying the plaintext matrix by the key matrix and
applying modulo 26 to the result.
● Inverse Key Matrix: For decryption, the inverse of the key matrix is used. This
matrix allows for recovering the plaintext from the ciphertext.
Flow Chart Steps:
1. Start.
2. Input the plaintext and key matrix.
3. Convert the plaintext into numerical values (A=0, B=1, ..., Z=25).
4. Divide the plaintext into blocks of the same size as the key matrix (e.g., 2-letter or 3-
letter blocks).
5. For each block of plaintext:
o Multiply the block by the key matrix.
o Apply modulo 26 to each element of the resulting matrix to get the
corresponding ciphertext block.
6. Combine all the ciphertext blocks to form the final ciphertext.
7. For decryption:
o Use the inverse of the key matrix.
o Multiply the ciphertext blocks by the inverse key matrix.
o Apply modulo 26 to recover the plaintext.
8. Output the ciphertext (for encryption) or plaintext (for decryption).
9. End.
Pseudo Code:
Input: Plaintext, Key Matrix
Output: Ciphertext (for encryption) / Plaintext (for decryption)
1. Start
2. Convert the plaintext into numerical values (A=0, B=1, ..., Z=25).
3. Divide the plaintext into blocks according to the size of the key matrix.
4. For each block:
a. Multiply the block by the key matrix.
b. Apply modulo 26 to each element of the resulting matrix.
5. Combine the processed blocks to form the ciphertext.
6. For decryption:
a. Use the inverse of the key matrix.
b. Multiply the ciphertext blocks by the inverse key matrix.
c. Apply modulo 26 to recover the plaintext.
7. Output the ciphertext or plaintext.
8. End