Skip to content

Instantly share code, notes, and snippets.

@enedil
Last active July 5, 2020 15:21
Show Gist options
  • Save enedil/a4ea63dbfef39a6a07af8c3afb030dc9 to your computer and use it in GitHub Desktop.
Save enedil/a4ea63dbfef39a6a07af8c3afb030dc9 to your computer and use it in GitHub Desktop.
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