vnosri's picture
sophia
8332c01
raw
history blame contribute delete
No virus
1.17 kB
# Define the substitution key
key = "C X Y B W P R V Q J Z M N T K E L D F G H I O U S"
# Define the plaintext and ciphertext functions
def encrypt(message,dic):
ciphertext = ""
for char in message:
if char.isalpha():
# Check if char is uppercase or lowercase
if char.isupper():
# Convert to lowercase and encrypt using key
encrypted = key[ord(char) - ord("A")].lower()
else:
# Convert to uppercase and encrypt using key
encrypted = key[ord(char) - ord("a")].upper()
ciphertext += encrypted
return ciphertext
def decrypt(message,dic):
plaintext = ""
for char in message:
if char.isalpha():
# Check if char is uppercase or lowercase
if char.isupper():
# Convert to lowercase and decrypt using inverse key
decrypted = key[25 - key.index(char.lower())].upper()
else:
# Convert to uppercase and decrypt using inverse key
decrypted = key[25 - key.index(char)].lower()
plaintext += decrypted
return plaintext