Skip to content

Instantly share code, notes, and snippets.

@lukealbao
Created February 11, 2015 16:51
Show Gist options
  • Save lukealbao/42ab2618b8e95dea97f6 to your computer and use it in GitHub Desktop.
Save lukealbao/42ab2618b8e95dea97f6 to your computer and use it in GitHub Desktop.
string => number
def encode(text, decode=False):
"Credit for this strategy goes to http://stackoverflow.com/a/16872684"
table = {'a':2, 'b':3, 'c':5, 'd':7, 'e':11, 'f':13, 'g':17, 'h':19,
'i':23, 'j':29, 'k':31, 'l':37, 'm':41, 'n':43,'o':47, 'p':53, 'q':59,
'r':61, 's':67, 't':71, 'u':73, 'v':79, 'w':83, 'x':89, 'y':97, 'z':101}
if not decode:
return reduce(mul,[table[char] for char in text]) if text else ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment