*******PYTHON creating a code that can encrypt and decrypt whatever is provided by the user... I need help getting my code to actually work********
For this problem, you will implement a cryptographic method, called the Vigenere cipher.
You will need to begin by implementing certain functions that perform the encryption and decryption. The core of it all is the basic shift function, which I will give you here:
def shift(ch,k):
return chr(ord('a')+(ord(ch)-ord('a')+k)%26)
Here ch is a character and k is an integer, the shift amount
You should implement functions that call shift, for encrypting and decrypting individual characters:
char_encrypt(plaintextchar,keychar)
char_decrypt(ciphertextchar,keychar)
We have provided you with the following pre_process function that gets rid of all spaces and punctuation and converts all characters to lowercase.
def preprocess(plaintext):
translator=str.maketrans('','',string.punctuation)
plaintext=plaintext.translate(translator).lower()
return plaintext.lower().replace(" ", "")
We have also provided you with the following repeattoatleastlength function that makes the key the same length as the plaintext message.
def repeat_to_at_least_length(key, length):
return key * (length//len(key) + 1)
Finally, put the pieces together to write the encryption and decryption algorithms
vig_encrypt(plaintext,key)
vig_decrypt(ciphertext,key)
None of these functions is very long, and some of it is quite repetitive, since char_encrypt and char_decryptare almost identical, and vig_decrypt and vig_encrypt are almost identical except for the inclusion of a pre-processing step in vig_encrypt.
mw. The function takes in a string, makes all characters lowercase, and removes all punctuation including spac
*******PYTHON creating a code that can encrypt and decrypt whatever is provided by the user... I need help getting my co
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
*******PYTHON creating a code that can encrypt and decrypt whatever is provided by the user... I need help getting my co
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!