I am new to cryptography so I try to make a simple Caesar cipher program with python but it keeps returning only one letter. Can anyone help please? Here's my code:
def main():
text = raw_input('input plainteks:')
key = int(raw_input('input key:'))
print("plain teks :"+text)
print("key :" +str(key))
print("hasil cipher:", encrypt(text,key))
def encrypt(text,key):
hasil = ''
for i in range(len(text)): #
char = text[i]
if (char.isupper()):
hasil += chr((ord(char) + key-65)%26 + 65)
else:
hasil += chr((ord(char) + key-97)%26 + 97)
return hasil
Here when I try to run it:
input plainteks:melody
input key:3
plain teks :melody
key :3
hasil cipher: b