Skip to content

Instantly share code, notes, and snippets.

@rgov
Created March 29, 2016 17:17
Show Gist options
  • Select an option

  • Save rgov/9d97371566d002e9393cde6c0178fed7 to your computer and use it in GitHub Desktop.

Select an option

Save rgov/9d97371566d002e9393cde6c0178fed7 to your computer and use it in GitHub Desktop.
def step_waves(waves):
for i in xrange(len(waves)):
if i + 1 < len(waves):
waves[i] += waves[i+1] - 8
# This is almost modulo 15, but not quite
if waves[i] > 15:
waves[i] -= 15
elif waves[i] < 0:
waves[i] += 15
return waves[0]
def setup_waves(key):
waves = [ int(key[i], 16) for i in xrange(len(key)) ]
for _ in xrange(1024):
step_waves(waves)
return waves
def crypt(key, message):
output = []
waves = setup_waves(key)
for m in message:
hi = (ord(m) / 16) ^ step_waves(waves)
lo = (ord(m) % 16) ^ step_waves(waves)
output.append(16 * hi + lo)
return ''.join(chr(o) for o in output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment