Question

In: Computer Science

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.

Solutions

Expert Solution

def new_alph(ch):
ch = ch.lower()
alph = 'abcdefghijklmnopqrstuvwxyz'
new_alph = alph[alph.index(ch):] + alph[:alph.index(ch)]
return new_alph
  

def encrypt(text, big_key):
res = ''
alph = 'abcdefghijklmnopqrstuvwxyz'
i = 1
for char in big_key:
new = new_alph(char)
for t in text:
if alph.count(t) == 1 :
res += new[alph.index(t)]
text = text[i:]
break
elif alph.count(t.lower()) == 1:
res += new[alph.index(t.lower())].upper()
text = text[i:]
break
else:
res += t
text = text[i:]
break
i += 1
return res
  
  
def decrypt(text, big_key):
res = ''
alph = 'abcdefghijklmnopqrstuvwxyz'
i = 1
for char in big_key:
new = new_alph(char)
for t in text:
if alph.count(t) == 1 :
res += alph[new.index(t)]
text = text[i:]
break
elif alph.count(t.lower()) == 1:
res += alph[new.index(t.lower())].upper()
text = text[i:]
break
else:
res += t
text = text[i:]
break
i += 1
return res
  
text1 = input("Enter Plain text to encypt: ")
key = input("Enter key : ")

if len(key) <= len(text1):
big_key = key * (len(text1) // len(key)) + key[:len(text1) % len(key)]
text_encrypt = encrypt(text1, big_key)

print('|Your text: "' + text1 + '"')
print('|Your key : "' + key + '"')
print('|Ans : ' + text_encrypt)
text_dec = input("Enter encrypted text to get plaintext : ")
text_decrypt = decrypt(text_dec, big_key)
key1 = input("Enter key : ")

print('|Your text: "' + text_dec + '"')
print('|Your key : "' + key1 + '"')
print('|Ans : ' + text_decrypt)

else:
print('Error: len(key)>len(text) ')

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and i can edit and change the answers if you argue, thanks :)


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.
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 Java program that will encode plain text into cipher text and decode cipher text...
Write a Java program that will encode plain text into cipher text and decode cipher text into plain text. Create following methods and add them to your class: • a method named encode(String p, int key) that takes a plain text p and encodes it to a cipher text by adding the key value to each alphabet character of plain text p using the ASCII chart. The method should return the encoded String. For example, if p = "attack at...
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
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 complete Python program that asks the user for a line of text (not just...
Write a complete Python program that asks the user for a line of text (not just a single word), and then tells the user whether the string is a palindrome (same forward and backward) if you ignore case and non-alphabetic characters. The following methods and functions may be useful: str.upper(), str.isalpha() -> bool, reversed(str) -> sequence, str.find(str) -> int, str.replace(str, str), str.center(int). Unless otherwise specified, they all return a string.
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)
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 class Select a free ebook and download the plain text file (utf8). Write a program...
Python class Select a free ebook and download the plain text file (utf8). Write a program that does the following: Read in your ebook (any book, any language) Break the book into words (look at .split() for strings) Make a dictionary of all words and how often they occur: for instance if the word'the' happened 2000 time and the word'a' happened 1940 times word_dict= {'the' : 2000, 'a' :1940} Print the dictionary of word frequencies to a file (freqs.txt) with...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT