def odd_even_encrypt(message):
"""Encrypts a message using the odd-even transposition cipher."""
odd_chars = ""
even_chars = ""
for i, char in enumerate(message):
if i % 2 != 0: # Check if index is odd
odd_chars += char
else:
even_chars += char
return odd_chars + even_chars
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
# Get user input
user_message = input("Enter a message to encrypt: ")
# 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)
Encryption program in python:
import random
import string
chars = " " + string.punctuation + string.digits + string.ascii_letters
chars = list(chars)
key = chars.copy()
random.shuffle(key)
#ENCRYPT
plain_text = input("Enter a message to encrypt: ")
cipher_text = ""
for letter in plain_text:
index = chars.index(letter)
cipher_text += key[index]
print(f"original message : {plain_text}")
print(f"encrypted message: {cipher_text}")
#DECRYPT
cipher_text = input("Enter a message to encrypt: ")
plain_text = ""
for letter in cipher_text:
index = key.index(letter)
plain_text += chars[index]
print(f"encrypted message: {cipher_text}")
print(f"original message : {plain_text}")