Spaces:
Runtime error
Runtime error
File size: 1,174 Bytes
d7992f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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
|