You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
722 B
31 lines
722 B
def Encrypt(text, key):
|
|
result = ""
|
|
for i in range(len(text)):
|
|
char = text[i]
|
|
if(char==" "):
|
|
result+=" "
|
|
elif (char.isupper()):
|
|
result += chr((ord(char) + key-65) % 26 + 65)
|
|
else:
|
|
result += chr((ord(char) + key - 97) % 26 + 97)
|
|
return result
|
|
|
|
|
|
|
|
def Decrypt(text, key):
|
|
result = ""
|
|
for i in range(len(text)):
|
|
char = text[i]
|
|
if(char==" "):
|
|
result+=" "
|
|
elif (char.isupper()):
|
|
result += chr((ord(char) - key-65) % 26 + 65)
|
|
else:
|
|
result += chr((ord(char) - key - 97) % 26 + 97)
|
|
return result
|
|
|
|
|
|
|
|
print(Encrypt("Hello world", 29))
|
|
print(Decrypt("Khoor zruog", 29))
|