-
-
Save enedil/a4ea63dbfef39a6a07af8c3afb030dc9 to your computer and use it in GitHub Desktop.
This file contains 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 read_data(path): | |
with open(path) as f: | |
q = int(next(f)) | |
rest = f.read().replace('L', '') | |
return q, eval(rest) | |
n, rest = read_data('flag.enc') | |
FF = GF(n) | |
def logarithm_mod_2(h): | |
return int(h^((n-1)/2) != 1) | |
A = Matrix(Zmod(2), [[logarithm_mod_2(FF(x)) for x in row] for row, _ in rest]) | |
b = vector(Zmod(2), [logarithm_mod_2(FF(x)) for _, x in rest]) | |
# one bit is skipped | |
l = [0] + list(A\b) | |
print(bytes([int(''.join(map(str, l[k:k+8])), 2) for k in range(0, len(l), 8)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment