Smithy Code
Fredrik Lundh | April 2006 | Originally posted to online.python.net
$ more smithy_code.py
from string import uppercase as alphabet
from itertools import izip, cycle
import sys
smithy_code = "JAEIEXTOSTGPSACGREAMQWFKADPMQZVZ"
def fib(n): # from the python tutorial
a, b = 0, 1
while b < n:
yield b
a, b = b, a+b
def decode(code):
for c, d in izip(code, cycle(fib(len(alphabet)))):
yield alphabet[(alphabet.index(c) + d - 1) % len(alphabet)]
sys.stdout.writelines(decode(smithy_code))
$ python smithy_code.py
JAFKIEFISTHRWHOAREBOUDREADQOUGHT
