Skip to content

Instantly share code, notes, and snippets.

@LucianU
Created October 30, 2025 15:01
Show Gist options
  • Select an option

  • Save LucianU/f71dce1af862584184ff7e197a0c5676 to your computer and use it in GitHub Desktop.

Select an option

Save LucianU/f71dce1af862584184ff7e197a0c5676 to your computer and use it in GitHub Desktop.
from math import gcd
A = [
174383810491743830225526218886287207533,
191898588380470994796266700002182515717,
108820603600940618360722782640387198241,
28574471588060987423539859812861556763,
172011087897023844205124286337241769048,
250552366381352896489045147880398294362
]
def main():
D, m = solve_for_m(A)
print(f"m: {m}")
x = get_x(D, m)
print(f"x: {x}")
y = get_y(A, x, m)
print(f"y: {y}")
check_As(A, x, y, m)
next_A = get_next_A(A, x, y, m)
print(f"Next A is {next_A}")
def solve_for_m(A):
D = []
index = len(A) - 1
while index > 0:
D.append(A[index] - A[index-1])
index -= 1
D.reverse()
R = []
index = len(D) - 1
while index > 1:
R.append(abs(D[index]*D[index-2] - D[index-1]**2))
index -= 1
return D, gcd(*R)
def get_x(D, m):
return (D[1] * pow(D[0], -1, m)) % m
def get_y(A, x, m):
return (A[1] - x*A[0]) % m
def check_As(A, x, y, m):
index = 1
while index < len(A):
calculated_A = (x * A[index-1] + y) % m
match = "yes" if A[index] == calculated_A else "no"
print(f"A[{index}]: {match}")
index += 1
def get_next_A(A, x, y, m):
return (x * A[-1] + y) % m
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment