python lecture
python lecture
def odd_even_decrypt(ciphertext):
"""Decrypts a ciphertext using the odd-even transposition cipher."""
length = len(ciphertext)
odd_length = length // 2
even_length = length - odd_length
odd_chars = ciphertext[:odd_length]
even_chars = ciphertext[odd_length:]
plaintext = ""
for i in range(even_length):
plaintext += even_chars[i]
if i < odd_length:
plaintext += odd_chars[i]
return plaintext
# Encryption
encrypted_message = odd_even_encrypt(user_message)
print("Encrypted message:", encrypted_message)
# Decryption
decrypted_message = odd_even_decrypt(encrypted_message)
print("Decrypted message:", decrypted_message)
import random
import string
chars = " " + string.punctuation + string.digits + string.ascii_letters
chars = list(chars)
key = chars.copy()
random.shuffle(key)
#ENCRYPT
cipher_text = ""
index = chars.index(letter)
cipher_text += key[index]
#DECRYPT
plain_text = ""
index = key.index(letter)
plain_text += chars[index]
print(f"encrypted message: {cipher_text}")