Skip to content

Instantly share code, notes, and snippets.

@fuyufjh
Last active December 21, 2015 12:43
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 fuyufjh/dee0939fe62147f514b6 to your computer and use it in GitHub Desktop.
Save fuyufjh/dee0939fe62147f514b6 to your computer and use it in GitHub Desktop.
Huawei Hackthon Nnajing 2015 Solution
#!/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