Created
March 29, 2016 17:17
-
-
Save rgov/9d97371566d002e9393cde6c0178fed7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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