Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program a Python program that creates a ciphertext gener-ated by the Vigen`ere c

ID: 3748133 • Letter: P

Question

Program a Python program that creates a ciphertext gener-ated by the Vigen`ere cipher. Pick a long text novel, in the range 200k characters or more, from google and use it as your plaintext. Choose a 3 to 5 characters keyword, encrypt the plaintext, and perform the crypltanalysis on the ciphertext to determine the keylenght and the keyword. Show all your steps in performing the cryptanalysis. The Caeser cipher is a substitution cipher where each letter in the plaintext is replaced with a letter that is with distance n from the original letter in the alphabet. The distance n is the key for the cipher. The encryption using the Caeser cipher for some letter using a key n is expressed as: =E(x) (x+ n) mod 26 To decrypt·Caner ciplier with a kry for each letter y in the ciphertext find the D(y)-(y-n) mod 26 x The Vigenère cipher is a modified version of the Caeser cipher by using the letters of a repeated keyword to encrypt the plain text.

Explanation / Answer

MAX_KEY_SIZE = 26

def getMode():

while True:

       print('Do you wish to encrypt or decrypt a message?’)

      mode = input().lower()

     if mode in 'encrypt e decrypt d'.split():

                                  return mode

                  else:

                    print('Enter either "encrypt" or "e" or "decrypt" or "d".')

def getMessage():

print('Enter your message:')

return input()

def getKey():

key = 0

while True:

                print('Enter the key number (1-%s)' % (MAX_KEY_SIZE))

key = int(input())

if (key >= 1 and key <= MAX_KEY_SIZE):

   return key

def getTranslatedMessage(mode, message, key):

if mode[0] == 'd':

key = -key

translated = ''

for symbol in message:

if symbol.isalpha():

num = ord(symbol)

num +=key

if symbol.isupper():

   if num > ord('Z'):

num -= 26

   elif num < ord('A')

num += 26

             elif symbol.islower():

if num > ord('z'):

num -= 26

                 elif num < ord('a’):

num += 26

translated += chr(num)

else:

translated += symbol

return translated

mode = getMode()

message = getMessage()

key = getKey()

print('Your translated text is:')

print(getTranslatedMessage(mode, message, key))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote