Posted on

# Write a program that encodes an input plaintextxwith a one-time pad.Start by assigning a number to each letter,a→0,…,z→25, using string.asciilowercase to get the alphabet.

Write a program that encodes an input plaintextxwith a one-time pad.Start by assigning a number to each letter,a→0,…,z→25, using string.asciilowercase to get the alphabet. For simplicity, you can assume that x contains only the letters a,b,c,…z.First write two functions that you can use to convert a given text intoa list of numbers (and back to the ̈uck).Now you can encode the plaintext by linking it to the one-time pad. Use a list of random numbers from 0 to 25 as the one-time pad, which is exactly as long as the plaintext x to be encrypted. To encrypt, calculate (digit by digit) x⊕p, where ⊕ means a bitwise xor ˆ. Now output the generated ciphertext y to the user.The programme should also be able to decrypt again. What plaintext do you get if you give y = [21, 16, 20, 4, 22, 6, 14, 2, 2, 29, 17, 5, 16,27, 20, 24, 3, 26, 7, 23, 9, 4, 26, 0, 12, 19, 22, 16, 28, 6, 30, 4,11, 20, 18, 22, 10, 5, 12, 6, 3, 24, 11, 12, 20, 21, 15, 16, 31, 22,25, 29, 22, 4, 31, 2, 9, 26]with p = ‘gxqfawxkruthfijhwvlpenalrcctbycrvfsdwgxcliaylqgiyovxqssrtdi’decrypt? To decrypt you must calculate y⊕p (p has been converted toletters here).Encryption with the one-time pad is perfectly secure, i.e. it is impossible to draw conclusions about the plaintext from the ciphertext without knowing the key. For this, however, the key must be randomly generated and may only be used once. You get all 6 points if the solution does not contain any loops (use List Comprehensions!) Note: with a bitwise xor, the two numbers are xor-linked to each other bit by bit in binary representation. The operator ˆ does exactly that, so you do not have to convert the numbers into binary representation yourself. I.e. 5 ˆ 3 results in 6,because 00000101⊕00000011 = 00000110