Last active
December 21, 2015 12:43
-
-
Save fuyufjh/dee0939fe62147f514b6 to your computer and use it in GitHub Desktop.
Huawei Hackthon Nnajing 2015 Solution
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
__author__ = 'Eric Fu' | |
cipher_file = open('cipher.txt', 'r') | |
dict_file = open('dictionary.tsv', 'r') | |
matrix = [] | |
for line in dict_file.readlines(): | |
words = line.strip().split('\t') | |
matrix.append(words) | |
plain = '' | |
prev_x, prev_y = 0, 0 | |
for cipher in cipher_file.readlines(): | |
cipher = int(cipher) | |
x = ((cipher >> 18) & 0x7f) | |
prev_x, x = x, x ^ prev_x | |
y = ((cipher >> 2) & 0x7f) | |
prev_y, y = y, y ^ prev_y | |
plain = plain + matrix[x - 1][y - 1] | |
cipher_file.close() | |
dict_file.close() | |
print(plain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment