Question

In: Computer Science

PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...

PYTHON

Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user

For Encryption Process:

Take the string and reverse the string.

Encrypt the reverse string with each character replaced with distance value (x) given by the user.

For Decryption:

Take the string and reverse the string.

Decrypt the reverse string with each character replaced with distance value (x) given by the user.

Sample

String input - udc

Encryption process – udc -> xgf (encrypted)

The program should ask the user for input to encrypt, and then display the resulting encrypted output. Next your program should ask the user for input to decrypt, and then display the resulting decrypted output.

Example

Enter phrase to Encrypt (lowercase, no spaces): udc

Enter distance value: 3

Result: xgf

Enter pharse to Decrypt: (lowercase, no spaces): xgf

Enter distance value: 3

Result: udc

Solutions

Expert Solution

Python 3 code

============================================================================================

inputmsg=input('Enter phrase to Encrypt (lowercase, no spaces): ')
distance=int(input('Enter distance value: '))

#encryption

#reverse a string
revstr=""
for i in inputmsg:
revstr=i+revstr

#print('reverse string is:',revstr)

encryptmsg=""

for i in range(len(revstr)):
  
encryptmsg+=chr((ord(revstr[i]) + distance - 97) % 26 + 97)

print("Result: ",encryptmsg)


#decoding

inputmsg1=input('Enter phrase to Encrypt (lowercase, no spaces): ')
distance1=int(input('Enter distance value: '))

#decryption
#reverse a string
revstr1=""
for i in inputmsg1:
revstr1=i+revstr1

demsg=""

for i in range(len(revstr1)):
demsg+=chr((ord(revstr1[i]) - distance1 - 97) % 26 + 97)

print("Result: ",demsg)


  

============================================================================================

Output


Related Solutions

Write a program that encrypts and decrypts the user input. Note – Your input should be...
Write a program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x) given by...
Desc: Encrypts or decrypts a file. Input: The user supplies the character '1' to encrypt, or...
Desc: Encrypts or decrypts a file. Input: The user supplies the character '1' to encrypt, or '2' to decrypt via the keyboard.   The user also supplies the name of the source file via the keyboard.   Output: If the user wants to encrypt, the text in input file is encrypted and the encrypted text is stored in "encrypted.txt". The original file is not changed. If the user wants to decrypt, the text in input file is decrypted and the decrypted text...
Create a Columnar Transposition Cipher in Python that encrypts/decrypts the word "Crypt".
Create a Columnar Transposition Cipher in Python that encrypts/decrypts the word "Crypt".
You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your...
You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your program will use two constant strings. One will represent the code for encryption: going from the original message (called the plaintext) to the encrypted version of the message. The other will be “abcdefghijklmnopqrstuvwxyz” (the lowercase alphabet. Your program will ask the user whether they want to 1) encrypt a message, 2) decrypt a message, or 3) quit. If they choose encrypt or decrypt, you...
Python Program 1: Write a program that takes user input in the form of a string...
Python Program 1: Write a program that takes user input in the form of a string Break up the string into a list of characters Store the characters in a dictionary The key of the dictionary is the character The value of the dictionary is the count of times the letter appears Hint: remember to initialize each key before using Output of program is the count of each character/letter Sort the output by key (which is the character) Python Program...
Step by step in python Write a program that will keep asking for a user input...
Step by step in python Write a program that will keep asking for a user input (until a blank line is entered) and will inform me whether what I entered was a valid number or not (without crashing). The program should use at least one try/except loop The program should include at least two custom written functions (a main() function can count as one of the two)
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
Write a code in Python jupytoer note book: Ask the user to input a year. Check...
Write a code in Python jupytoer note book: Ask the user to input a year. Check if this is a leap year or not. Ask the user to input a number. Check if this number is even or odd. HbA1c of 6.5% or higher indicates diabetes. 5.7 to 6.4 indicates pre-diabetes. HbA1c less than 5.7 is considered normal. Ask the user for their HbA1c level and display if their they are in the normal range, pre-diabetic, or diabetic. Ask the...
PYTHON Write a program that accepts a range of input from the user and checks whether...
PYTHON Write a program that accepts a range of input from the user and checks whether the input data is sorted or not. If the data series is already sorted your program should print “True” or should print “False” otherwise. You should not use any sort function for this program. Input: How many numbers you want to input: 3 # user input 3 Input the number: 5 Input the number: 2 Input the number: 7 Output: False
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT