Question

Write a script that inputs a line of encrypted text and a distance value and outputs...

Write a script that inputs a line of encrypted text and a distance value and outputs plaintext using a Caesar cipher. The script should work for any printable characters.

An example of the program input and output is shown below:

Enter the coded text: Lipps${svph% Enter the distance value: 4 Hello world!

# Request the inputs
codedText = input("Enter the coded text: ")
distanceValue = int(input("Enter the distance value: "))
# Calculate the decryption
plainText = ""
for cr in code:
ordvalue = ord(ch)
cipherValue = ordvalue - distance
if cipherValue < ord('a'):
cipherValue = ord('z') - \ (distance - (ord('a') - ordvalue - 1))
plainText += chr(cipherValue)
print(plainText)
  

This code needs to be edited to be correct. We are using the newest form of python which I believe is 3.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Request the inputs
codedText = input("Enter the coded text: ")
distanceValue = int(input("Enter the distance value: "))
# Calculate the decryption
plainText = ""
for ch in codedText:
    ordvalue = ord(ch)
    cipherValue = ordvalue - distanceValue
    plainText += chr(cipherValue)
print(plainText)

Add a comment
Know the answer?
Add Answer to:
Write a script that inputs a line of encrypted text and a distance value and outputs...
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
  • So I wrote a script that inputs a line of plaintext and a distance value and...

    So I wrote a script that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher. The script should work for any printable characters: plainText = input("Enter a message: ") distance = int(input("Enter the distance value: ")) code = "" for ch in plainText: ordValue = ord(ch) cipherValue = ordValue + distance if cipherValue > 127: cipherValue = distance - (127 - ordValue + 1) code += chr(cipherValue) print(code) Now I need...

  • Write a script in python that inputs a line of plaintext and a distance value and...

    Write a script in python that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher. The script should work for any printable characters.

  • Python Programing Exercise 4.1

    Write a script that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher.

  • Using Python; Caesar part of the homework: Write c_encrypt() and c_decrypt(), both of which take two...

    Using Python; Caesar part of the homework: Write c_encrypt() and c_decrypt(), both of which take two arguments, the first one a string and the second one an integer key. Both should return a string. Vigenère part of the homework: Write vig_encrypt() and vig_decrypt() functions. Each takes two strings as inputs, with the first being the plaintext/ciphertext, and the second being the key. Both should be calling functions you wrote earlier to help make the work easier. The key will be...

  • The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”....

    The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”. Write Java or Python code to implement Shift cipher(Encryption and Decryption) and test your code on given plaintext. Your code must meet following conditions. (5 points) User must enter the value of key from command prompt and print it at command prompt. (2.5 points) Print the cipher text and the plaintext at the command prompt after encryption and decryption. (2.5 points) Test your algorithm...

  • Please can I have a UML Class diagram for the Python program below: def main(): print()...

    Please can I have a UML Class diagram for the Python program below: def main(): print() print("Welcome to Caesar Encryption and Viginere Decryption Cipher") print() print("Please select an option") option = "c" while option == "c": hello = input('Choose Caesar Cipher encrypt 1:\n' 'Choose Viginere Cipher Decrypt 2:\n') message = input('Enter a message: ') password = input('Enter a password: ') if hello == '1': viginere_cipher(message, password) elif hello == '2': viginere_cipher_decrypt(message, password) print() print("Choose an option") option = input('Enter c...

  • . Please write a function that will do the following Decryption of a message encrypted with a substitution cipher given cipher text only without any key Please provide comments on each line of code ou...

    . Please write a function that will do the following Decryption of a message encrypted with a substitution cipher given cipher text only without any key Please provide comments on each line of code outlining what that line is doing. Note: Only the Function is to be written, all user inputs i.e the text to be decrypted will be entered earlier in the program. Code must be written in C and be able to be compiled using GCC If any...

  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • python Programming Exercise 4.7 Write a script that decrypts a message coded by the method used...

    python Programming Exercise 4.7 Write a script that decrypts a message coded by the method used in Project 6. Method used in project 6: Add 1 to each character’s numeric ASCII value. Convert it to a bit string. Shift the bits of this string one place to the left. A single-space character in the encrypted string separates the resulting bit strings. An example of the program input and output is shown below: Enter the coded text: 0010011 1001101 1011011 1011011...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

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