Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Created November 19, 2024 08:23
Show Gist options
  • Save thomwiggers/8abb0879c463f2814cae92f93e49306b to your computer and use it in GitHub Desktop.
Save thomwiggers/8abb0879c463f2814cae92f93e49306b to your computer and use it in GitHub Desktop.
import random
F = GF(97)
points = [
(F(x), F(y))
for (x, y) in (
( 2, 60),
( 3, 2),
( 4, 18),
( 5, 66),
( 6, 9),
( 7, 87),
( 8, 45),
( 9, 83),
(10, 85),
(11, 70),
(12, 75),
(13, 15),
(14, 95),
(15, 26),
(16, 57),
(17, 21),
(18, 24),
(19, 66),
(20, 48),
(21, 21),
(22, 50),
(23, 53),
(24, 28),
(26, 55),
(27, 18),
(28, 78),
(29, 81),
)
]
print("Aantal punten:", len(points))
R = F['x']
f_ = R.lagrange_polynomial(points)
def recover(points):
f = R.lagrange_polynomial(points)
assert f.degree() == f_.degree(), f"Degree is wrong? {f.degree()}"
assert f(0) == f_(0), f"Afwijkende oplossing: {f(0)}"
print("Oplossing:", f(0))
recover(points)
for i in range(100):
sample = random.sample(points, 26)
recover(sample)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment