Question: Your task for this assignment is to write a Python3 program that: Reads in from standard input (i.e. keyboard) a list of keyword and message
Your task for this assignment is to write a Python3 program that:
Reads in from standard input (i.e. keyboard) a list of keyword and message pairs, one pair per line. The keyword and message are each a single word, separated by a space, all in uppercase.
The first line of input is a number n, followed by n lines. Each line may have two words, thekeyword and the message.
If the line contains more (or less) than two strings, the program should output "ERROR" and continue to the next line.
For each keyword/message pair, the program creates a key table using the keyword and encrypts the message using the Playfair cipher, and outputs the encrypted message.
Sample Input/output
Input:
3
GUIDE UNIVERSITY
ENGLISH
KNOW ALBERTA
Output:
EKUWDSQEVZ
ERROR
FSCFMYFA
Hint
To represent the key table, you may want to use a list, where each of its five elements is a five letter string representing a row. An easy way to do this is to start with a twenty-five letter string, for example:
table = [keyString[i:i+5] for i in range(0, len(keyString), 5)]
will give the following result for the table:
['PLAYF', 'IREKS', 'MBCDG', 'HJNOQ', 'TUVWZ']
To access the letter in the ith row and jth column of the table, you can use table[i][j]. In our example, table[1][3] is 'K'.
keyString = 'PLAYFIREKSMBCDGHJNOQTUVWZ'
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
