Skip to content

Instantly share code, notes, and snippets.

@packetchef
Created October 26, 2016 22:11
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 packetchef/db7f422ca9f51d9c7e67a2ffa74ec180 to your computer and use it in GitHub Desktop.
Save packetchef/db7f422ca9f51d9c7e67a2ffa74ec180 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import string
# Given startString, this loops through rot(n) until it is un-rotted back to original
# rot_alpha courtesy of http://eddmann.com/posts/implementing-rot13-and-rot-n-caesar-ciphers-in-python/
def rot_alpha(n):
from string import ascii_lowercase as lc, ascii_uppercase as uc
lookup = string.maketrans(lc + uc, lc[n:] + lc[:n] + uc[n:] + uc[:n])
return lambda s: s.translate(lookup)
startString = "This is my string"
rot = 14
transString = rot_alpha(rot)(startString)
checkString = ""
run = 1
while checkString != startString:
print("(Translation round: %02i) Start: %s | Trans: | %s" % (run, startString, transString))
checkString = transString
transString = rot_alpha(rot)(transString)
run += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment