Created
October 26, 2016 22:11
-
-
Save packetchef/db7f422ca9f51d9c7e67a2ffa74ec180 to your computer and use it in GitHub Desktop.
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
#!/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