Question

Python 3:In this problem, your input file will contain a number of ciphertext and key pairs,...

Python 3:In this problem, your input file will contain a number of ciphertext and key pairs, separated by a space. You may assume that the ciphertext contains only uppercase letters. However, it is possible that the key may be missing, and your program should handle this case.

The ciphertext has been encrypted by shifting letters in the alphabet by the amount specified by the key. The word HELLO with key = 2 becomes JGNNQ. Letters should wrap around, so PIZZA with key = 1 becomes QJAAB. If the key is missing, your program should output a message "Missing key!".

code.txt

CLGUBA 13

JGNNQ

ZKADQSZ 1

OQJ 4

AKNSR 2

NGBOXKLBMR 7

sample output

Enter the input filename: code.txt
PYTHON
Missing key!
ALBERTA
SUN
CMPUT
UNIVERSITY
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation::

  • Code in PYTHON is given below
  • Please read comments for better understanding of the code
  • Code is easy to understand
  • Screenshot of the code is also given for the problem of indentation
  • Output is given at the end

Code in PYTHON::

"""
Opening file named code.txt in object file
"""
file = open('code.txt')
"""
    Traversing each line in the file
    using for loop
"""
for i in file:
    """Removing newline characters at the end of the line"""
    str=i.rstrip()
    """Converting str into list[]"""
    str=str.split(' ')
    ''' If the length the str array is 1
    then it means that key is not there
    '''
    if len(str)==1:
        print("Missing key!")
    else:
        '''
        We store the key in variable named key
        '''
        key=int(str[1])
        '''
        And we strore the current string in string
        '''
        string=str[0]
        '''
        Below we traverse each character of the string
        and get ASCII value by using ord
        '''
        for i in string:
            val=int((ord(i)+key-65)%26)
            print(chr(val+65),end='')
        print()

Screenshot of the code::

OUTPUT::

Please provide the feedback!!

Thank You!!

Add a comment
Know the answer?
Add Answer to:
Python 3:In this problem, your input file will contain a number of ciphertext and key pairs,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...

    WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...

  • Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple...

    Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a certain fixed amount (the amounts represents the encryption key). The resulting encoded text is called ciphertext. Example Key (Shift): 3 Plaintext: Abc Ciphertext: Def Task Your goal is to implement a Caesar cipher program that receives the key and an encrypted paragraph (with uppercase and lowercase letters, punctuations, and...

  • Write a python program: Ask for the encryption key. The key must be a list of...

    Write a python program: Ask for the encryption key. The key must be a list of numbers between 0 and N-1, where N is the number of entries in the key's list; for example, 5,4,3,2,1,0 has six numbers, and each digit 0-5 appears in the list. Asks for a line of text to encrypt. Use the transposition key to transpose each chunk of N letters in input text. If the input text is not a multiple of the key length,...

  • Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt...

    Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a date is picked as December 18, 1946, then the 6 digits are 121846. Assume the dates are in the 20th century. To encrypt a message, you will shift each letter of the message by the number of spaces indicated by the corresponding digit. For example, to encrypt...

  • Write a simple program in Java or C, that will help you to figure out the...

    Write a simple program in Java or C, that will help you to figure out the key used for Vigenère encrypted file. For this exercise, assume the key length is less than five characters long and only English upper case letters from A-Z are used. You may also assume the plaintext contains only the upper case English letters from A-Z, ignore the space characters. Your program should take a ciphertext file (encrypted using the Vigenère encryption algorithm) as input and...

  • (The file should have your program and the console input/output of your program) 3.18: Pizza Pi...

    (The file should have your program and the console input/output of your program) 3.18: Pizza Pi Joe’s Pizza Palace needs a program to calculate the number of slices a pizza of any size can be divided into. The program should perform the following steps: Ask the user for the diameter of the pizza in inches. Calculate the number of slices that may be taken from a pizza of that size. Display a message telling the number of slices. To calculate...

  • Use PYTHON Write a program that will take an input file called input.txt which will contain a Jav...

    use PYTHON Write a program that will take an input file called input.txt which will contain a Java program and parse it and output an annotated version. Your program will track the nesting depth of the braces of the input file and will output an annotated version of the file. Your final program will 1. List the nesting depth of curly braces 2. Ignore braces inside quotes or comments Use Python Assume that all quoted strings begin and end on...

  • Write an LC-3 program (starting at memory location 0x3000) to take a string as input and...

    Write an LC-3 program (starting at memory location 0x3000) to take a string as input and then output information about this string. The end of the string will be denoted with the "#" character. Once the "#" has been found, output the following in order: 1) The letter “u” followed by the number of uppercase letters in the string (A-Z) 2) The letter “l” followed by the number of lowercase letters in the string (a-z) 3) The letter “n” followed...

  • Problem 1. A file that contain two columns of data are provided. You should write a...

    Problem 1. A file that contain two columns of data are provided. You should write a program that calculate the average of the two number in each row, and output them into a separate file. Some row contains non-numbers or may be missing an number, and your code should use Exception to catch these errors, and output an appropriate error message. For testing, your input data file should be: 1.2 3.5 one 4.4 2.5 three 4.1 9.9 1.9 18.5. 20.3

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT