Skip to content

Instantly share code, notes, and snippets.

@niklasl
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklasl/9551499 to your computer and use it in GitHub Desktop.
Save niklasl/9551499 to your computer and use it in GitHub Desktop.
import string
import math
CHARS = string.digits + string.lowercase
assert len(CHARS) == 36
CHARS += string.uppercase
assert len(CHARS) == 62
BASE64_CHARS = string.uppercase + string.lowercase + string.digits + "+/"
VOWELS = "auoeiy"
LPHNM_CHARS = "".join(c for c in CHARS if c.lower() not in VOWELS)
assert len(LPHNM_CHARS) == 50
def int2pos(a, b):
for i in xrange(int(math.log(a, b)), -1, -1):
yield (a/b**i) % b
def tostr(items, alphabet):
return ''.join(alphabet[i] for i in items)
def rotate(i, rotation, ceil):
j = i + rotation
if j >= ceil:
j = j - ceil
return j
if __name__ == '__main__':
alphabet = LPHNM_CHARS
base = 30
#import time
offset = 1394814000000 # int(time.time() * 1000)
for n in range(0, 999):
items = list(int2pos(n + offset, base))
rotation = items[-1]
scrambled = [rotate(i, rotation, base) for i in items[:-1]]
scrambled.append(rotation)
print tostr(items, alphabet), '=>', tostr(scrambled, alphabet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment