Last active
January 5, 2022 18:54
-
-
Save s0h1s2/d7d1ef2e012a745a47051ab12a7af41f to your computer and use it in GitHub Desktop.
caesar cipher implementation python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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