Created
March 9, 2014 06:03
python decoder ring
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
import string | |
alphabet = "abcdefghijklmnopqrstuvwxyz" | |
ring = "abcdefghijklmnopqrstuvwxyz" | |
if __name__ == "__main__": | |
offset = -1 | |
while not (0 <= offset <= len(alphabet)): | |
choice = raw_input("What is your key's offset?: ") | |
offset = int(choice) | |
print "Shifting ring by %d places..." % offset | |
ring = ring[offset:] + ring[0:offset] | |
print "(psst keep it safe!) new ring: %r" % ring | |
choice = raw_input("Encrypt = 1 Decrypt = 2: ") | |
message = raw_input("What is the message?: ") | |
out = "" | |
translation = None | |
if choice in ['1','2']: | |
if choice == '1': | |
translation = string.maketrans(alphabet, ring) | |
else: | |
translation = string.maketrans(ring, alphabet) | |
out = message.translate(translation) | |
print "Message: %s" % out | |
else: | |
print "Not a valid option. Exiting" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment