Ask coding questions

← Back to all posts
fixing the code
AhmadHamad3

ALPHABET = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alphabet = ' abcdefghijklmnopqrstuvwxyz'
number = ' 12345678910'
key = 5
#i want c to be checked if it is upper later then deciphered as upper later but if it is lower then it desiphered as lower and if it is number it desiphered as number

def caesar_encrypt(plain_text):
cipher_text = ''

plain_text = plain_text.upper()
for c in plain_text:
index = ALPHABET.find(c)
index = (index+key)%len(ALPHABET)
cipher_text = cipher_text + ALPHABET[index]
return cipher_text

plain_text = plain_text.lower()
for c in plain_text:
index = alphabet.find(c)
index = (index+key)%len(alphabet)
cipher_text = cipher_text + alphabet[index]
return cipher_text

def caesar_decrypt(cipher_text):
plain_text = ''
for c in cipher_text:
index = ALPHABET.find(c)
index = (index-key)%len(ALPHABET)
plain_text = plain_text + ALPHABET[index]

for c in cipher_text:
index = alphabet.find(c)
index = (index-key)%len(alphabet)
plain_text = plain_text + alphabet[index]

return plain_text

if name=="main":
encrypted = caesar_encrypt('This is AN Example')
print(encrypted)
decrypted = caesar_decrypt(encrypted)
print(decrypted)

Voters
AhmadHamad3
Comments
hotnewtop
MrVoo

Is this a question?

AhmadHamad3

yes i do not know how to connect these codes together to make the
sentence run prob @MrVoo

AhmadHamad3

i want c to be checked if it is upper later then deciphered as upper later but if it is lower then it desiphered as lower and if it is number it desiphered as number this is what i want the code to do @MrVoo

MrVoo

@AhmadHamad3 Attach the repl, I can't run code by looking at it.

AhmadHamad3
AhmadHamad3
MrVoo

@AhmadHamad3 Dont use .upper() then...?

AhmadHamad3

is it possible to send it to me in txt file @MrVoo

MrVoo

@AhmadHamad3 Uhhh cant you just change all .upper()s to .lower()