Question

In: Computer Science

Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get...

Cryptography and Applications

1. Write Python program to implement Caesar’s Cipher. Take user input to get plain text and key.

2.  Write a Python program to implement Vignere Cipher. Take user input to get plain text and key.

TRY TO MAKE IT AS EASY AS YOU CAN.

Solutions

Expert Solution

PART 1 -

CODE -

# Taking plain text and key as input from the user
plain_text = input("Enter Plain Text: ")
key = int(input("Enter key: "))
# Initializing cipher text with empty string
cipher_text = ""
# Iterating over each character of plain text
for i in range(len(plain_text)):
letter = plain_text[i]
# Encrypting uppercase characters
if letter.isupper():
cipher_text += chr((ord(letter) - 65 + key) % 26 + 65)
# Encrypting lowercase characters
else:
cipher_text += chr((ord(letter) - 97 + key) % 26 + 97)
# Displaying plain text and encrypted text
print("\n\nPlain Text: ", plain_text)
print("\nEncrypted Text: ", cipher_text)

SCREENSHOT -

PART 2 -

CODE -

# Taking plain text and key as input from the user
plain_text = input("Enter Plain Text: ")
key = input("Enter key: ")

# Initializing generated key with key
gen_key = key
# Checking if length of key is equal to length of plain text or not
if len(gen_key) != len(plain_text):
# Generating key in a cyclic manner until its length is equal to length of plain text
for i in range(len(plain_text) - len(key)):
gen_key += key[i % len(key)]

# Initializing cipher text with empty string
cipher_text = ""
# Iterating over each character of plain text
for i in range(len(plain_text)):
# Converting into letter number between 0-25
letter_num = (ord(plain_text[i]) + ord(gen_key[i])) % 26
# Converting into ASCII characters
if plain_text[i].islower():
cipher_text += chr(ord('A') + letter_num).lower()
else:
cipher_text += chr(ord('A') + letter_num)

# Displaying plain text and encrypted text
print("\n\nPlain Text: ", plain_text)
print("\nEncrypted Text: ", cipher_text)

SCREENSHOT -

If you have any doubt regarding the solution, then do comment.

Do upvote.


Related Solutions

Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get...
Cryptography and Applications 1. Write Python program to implement Caesar’s Cipher. Take user input to get plain text and key. 2.  Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
Write a Python program to implement Vignere Cipher. Take user input to get plain text and...
Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
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)...
write a progam in python that willl take user input for item and price and save...
write a progam in python that willl take user input for item and price and save them in a dictionary. Then print the item and price and the total price.
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.
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
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Need this program in python. The data must be taken from user as input. Write a...
Need this program in python. The data must be taken from user as input. Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is: Miles = Kilometers X 0.6214 Kilometers = Miles / 0.6214 Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles The conversion MUST be done...
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input...
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input a description of several process schedules (i.e., lists of send, receive or print operations). The output of your program will be a linearization of these events in the order actually performed, annotated with Lamport clock values. The input of the program will be a collection of processes, each with a list of operations to perform. The processes are named p1...pn for some n (you...
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT