Created
June 26, 2020 02:08
-
-
Save shadowdevnotreal/3d99165a304c6a09ead0fc483dcd4950 to your computer and use it in GitHub Desktop.
Simple Caesar Shifting Encryption Code
This file contains hidden or 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
| #Caesar Shift Encryption Code | |
| def encrypt(string, shift): | |
| cipher = '' | |
| for char in string: | |
| if char == ' ': | |
| cipher = cipher + char | |
| elif char.isupper(): | |
| cipher = cipher + chr((ord(char) + shift - 65) % 26 + 65) | |
| else: | |
| cipher = cipher + chr((ord(char) + shift - 97) % 26 + 97) | |
| return cipher | |
| text = input("enter string: ") | |
| s = int(input("enter shift number: ")) | |
| print("original string: ", text) | |
| print("after encryption: ", encrypt(text, s)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment