Skip to content

Instantly share code, notes, and snippets.

@maple3142
Created October 13, 2024 18:02
Show Gist options
  • Save maple3142/b0d47badb579d90257d6534411e0a33b to your computer and use it in GitHub Desktop.
Save maple3142/b0d47badb579d90257d6534411e0a33b to your computer and use it in GitHub Desktop.
GF multiply by constant to matrix multiplication
x = polygen(GF(2))
mod = x.parent().irreducible_element(8, algorithm='random')
F = GF(2^8, 'a', modulus=mod)
def get_multiply_matrix(mul, mod):
return mul.polynomial()(matrix.companion(mod))
mul = F.random_element()
T = get_multiply_matrix(mul, mod)
for _ in range(100):
r = F.random_element()
va = vector(r.polynomial().padded_list(8))
vb = vector((r * mul).polynomial().padded_list(8))
assert T * va == vb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment