Last active
December 15, 2015 09:45
-
-
Save henkman/9443511f89c0cf5d9450 to your computer and use it in GitHub Desktop.
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 string | |
| import sys | |
| import re | |
| if __name__ == "__main__": | |
| args = sys.argv[1:] | |
| decode = len(args) >= 2 and "d" == args[0] | |
| if decode: | |
| reDec = re.compile("(\d+)\*([^\d\*]*)") | |
| for s in args[1:]: | |
| r = "" | |
| for m in reDec.finditer(s): | |
| n = int(m.group(1)) | |
| if n > len(string.ascii_lowercase): | |
| continue | |
| r += string.ascii_lowercase[n] | |
| if m.group(2): | |
| r += m.group(2) | |
| print(r) | |
| else: | |
| for s in args[1:]: | |
| r = "" | |
| for c in s: | |
| i = string.ascii_lowercase.find(c.lower()) | |
| if i == -1: | |
| r += c | |
| continue | |
| r += "{0}*".format(i) | |
| print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment