This is a encrypted message passing technique. If you are interested read this question.
Digraph Cipher
Exchanging information securely has been a challenge and a fascination since the time human beings started communicating. A digraph cipher is an encryption mechanism that replaces each pair of letters in the plaintext (message to be encrypted) by another pair of letters. In order to encrypt and transmit a message, the sender and receiver must agree on a keyword. Before encryption, the letters of the alphabet are written in a 5x5 square (The Keyword is XTREM for all Encryptions), beginning with the keyword, and combining the elements I and J into a single cell. Next, the message is broken into pairs of letters called digraphs. So that each pair contains two unique letters, an x is added between any repeated letters that fall in the same pair or at the end to make a single final letter a digraph. All digraphs fall into one of three categories: both letters are in the same row; both letters are in the same column; or both letters are in different rows and columns. For encryption, letters in the same row are replaced by the letter to the immediate right of each one in the matrix. If a letter is at the end of a row, it is replaced by the letter at the beginning. Letters in the same column are replaced by the letter immediately below each one. If a letter is at the bottom of a row, it is replaced by the letter at the top. If the letters are in neither the same row nor the same column, the first letter is replaced by the letter in its row that is at the intersection with the column of the second letter. The second letter is replaced by the letter in its row that is at the intersection with the column of the first letter. The message is easily deciphered by the recipient using the same keyword.
Task
Please, write a program that takes a keyword and a message and returns the message in its encrypted format.
Encryption Square:
X T R E M
A B C D F
G H I/J K L
N O P Q S
U V W Y Z
Input
The program gets two unique inputs: the keyword and the message.
Valid assumptions:
1. Keyword contains only alphabets and message text contain only alphabets and spaces.
2. The message is only one line of text.
3. DO NOT include white spaces when comparing
4. Add X’s for double letters before adding X’s at the end to create an incomplete digraph
e.g. littles -> li tx tl e -> li tx tl ex
5. If I/J is selected as a digraph solution for a message, then the output should only be “I” (not IJ, J, I/J)
e.g. lp -> is
Output
The program outputs the given message in an encrypted form.
Sample InputKeyword: Xtreme
Message: This is fun
Sample Output
Message: Bolp lp azua
No comments:
Post a Comment