Skip to content

Instantly share code, notes, and snippets.

@henkman
Last active December 15, 2015 09:45
Show Gist options
  • Select an option

  • Save henkman/9443511f89c0cf5d9450 to your computer and use it in GitHub Desktop.

Select an option

Save henkman/9443511f89c0cf5d9450 to your computer and use it in GitHub Desktop.
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