Lab #5. Task 1: You Need To Encrypt The Following Example:: Vigenere Vigenere
Lab #5. Task 1: You Need To Encrypt The Following Example:: Vigenere Vigenere
Lab #5. Task 1: You Need To Encrypt The Following Example:: Vigenere Vigenere
Keyword: pen
Plaintext: theater
Example:
Input : Plaintext : GEEKSFORGEEKS
Keyword : AYUSH
Output : Ciphertext : GCYCZFMLYLEIM
For generating key, the given keyword is repeated
in a circular manner until it matches the length of
the plain text.
The keyword "AYUSH" generates the key "AYUSHAYUSHAYU"
The plain text is then encrypted using the process
explained below.
Encryption
The first letter of the plaintext, G is paired with A, the first letter of the key. So use
row G and column A of the Vigenere square, namely G. Similarly, for the second
letter of the plaintext, the second letter of the key is used, the letter at row E and
column Y is C. The rest of the plaintext is enciphered in a similar fashion.
Decryption
Decryption is performed by going to the row in the table corresponding to the key,
finding the position of the ciphertext letter in this row, and then using the column’s
label as the plaintext. For example, in row A (from AYUSH), the ciphertext G
appears in column G, which is the first plaintext letter. Next we go to row Y (from
AYUSH), locate the ciphertext C which is found in column E, thus E is the second
plaintext letter.
A more easy implementation could be to visualize Vigenere algebraically by
converting [A-Z] into numbers [0–25].
Encryption
The plaintext(P) and key(K) are added modulo 26.
Ei = (Pi + Ki) mod 26
Decryption
Di = (Ei - Ki + 26) mod 26
Note: Di denotes the offset of the i-th character of the plaintext. Like offset of A is
0 and of B is 1 and so on.
Below is the implementation of the idea.
In C++:
cipher_text.push_back(x);
}
return cipher_text;
}
Output:
Ciphertext : GCYCZFMLYLEIM
Original/Decrypted Text : GEEKSFORGEEKS