Question

In: Computer Science

Using Python, write a simple application that takes user input of plaintext and key, and encrypt...

Using Python, write a simple application that takes user input of plaintext and key, and encrypt the plaintext with Vigenere Cipher. The application should then print out the plaintext and the ciphertext.

Solutions

Expert Solution

Note: The program is properly commented, if face any doubt leave a comment.

Program:

#Note: Use only capital letter

#Function to perform Vignere cipher conversion
def vignere_cipher(plain_text, key):
    
    #defining cipher_text variable to store variable
    cipher_text = ""
    
    #storing length of the key to l
    l = len(key)
    
    #we'll iterate through each character of the plain text
    for i in range(len(plain_text)):
        
        #Formula: Ci = (Pi + Ki) mod 26
        #Ci is the cipher text character's ASCII value
        #Pi is the plain text character's ASCII value
        #Ki is the corresponding key character's ASCII value
        
        x = (ord(plain_text[i]) + ord(key[i%l])) % 26
        x += ord('A')
        cipher_text += chr(x)
        
    #returning cipher text
    return cipher_text

#Calling the main program
plain_text = input('Enter plain text: ')
key = input('Enter key: ')
cipher_text = vignere_cipher(plain_text, key)
print('\n\nCipher text: ', cipher_text)

Output:

Leave a comment if face any doubt!! Happy coding!!


Related Solutions

Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write...
Java Code: Write an application that takes in user input. (Name, Age, and Salary) ------ Write an application that includes a constructor, user input, and operators.
Encrypt the given plaintext with the key. Built the key matrix (big size). And show how...
Encrypt the given plaintext with the key. Built the key matrix (big size). And show how you get each letter ciphertext (you can do that by making shapes and arrows in key matrix). No need to draw key matric again and again.    Show all your work. If you just write cipher text and key matric without showing (shapes and arrow on key matrix) that how you get the ciphertext then your marks will be deducted. key :  alphabets plaintext :   smartness
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
Using playfair cipher, encrypt the plaintext “SUCCESS” using the keyword “MIDTERMEXAM”
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)...
****USING BASH**** Write a function that takes an input temperature (Celsius or Fahrenheit) from the user...
****USING BASH**** Write a function that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin.
Write application in C# that enables a user to: Use Methods for user input and calculations...
Write application in C# that enables a user to: Use Methods for user input and calculations input the grade and number of credit hours for any number of courses. Calculate the GPA on a 4.0 scale using those values. Grade point average (GPA) is calculated by dividing the total amount of grade points earned, sometimes referred to as quality points, by the total number of credit hours attempted. For each hour, an A receives 4 grade or quality points, a...
Write a small program to encrypt and decrypt a message using Python library.
Write a small program to encrypt and decrypt a message using Python library.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT