Skip to content

Instantly share code, notes, and snippets.

@s0h1s2
Last active January 5, 2022 18:54
Show Gist options
  • Save s0h1s2/d7d1ef2e012a745a47051ab12a7af41f to your computer and use it in GitHub Desktop.
Save s0h1s2/d7d1ef2e012a745a47051ab12a7af41f to your computer and use it in GitHub Desktop.
caesar cipher implementation python
def encrypt(text,key):
if key>26:
key=key%26
result=''
for char in text:
asciiCode=ord(char)
if asciiCode>=65 and asciiCode<=122: ## if character between a ...Z
charCode=asciiCode+key
if charCode>122:
charCode=charCode-26
result+=chr(charCode)
else:
result+=char
return result
result=encrypt("helloworld!",2000)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment