Last active
October 18, 2020 00:29
-
-
Save JasonBristol/634f90d4e8339487fd59232d5ef703f4 to your computer and use it in GitHub Desktop.
Tiny python 3.x script to solve simple ceaser ciphers
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
import re | |
s = input("Please enter the cipher text: ") | |
place = input( | |
"Please enter the character index (optional): ") | |
shift = input("Please enter the shift key: ") | |
chars = "abcdefghijklmnopqrstuvwxyz" | |
exclude = " '\":;.,?!" | |
result = [] | |
exclude_count = 0 | |
for i, c in enumerate(s, start=1): | |
if c in exclude: | |
exclude_count += 1 | |
result.append(c) | |
elif place != "" and (i - exclude_count) % int(place) != 0: | |
result.append(c) | |
else: | |
idx = chars.index(c) | |
result.append(chars[idx - int(shift)]) | |
print("".join(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment