Skip to content

Instantly share code, notes, and snippets.

@JasonBristol
Last active October 18, 2020 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JasonBristol/634f90d4e8339487fd59232d5ef703f4 to your computer and use it in GitHub Desktop.
Save JasonBristol/634f90d4e8339487fd59232d5ef703f4 to your computer and use it in GitHub Desktop.
Tiny python 3.x script to solve simple ceaser ciphers
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