Advertisement
saleks28

BVA4

Aug 22nd, 2020
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. def generate_polynomial(F, q, f_x):
  2.     n = f_x.degree()  # n = deg(f)
  3.     QR.<x> = F.quotient(f_x)
  4.     while 1:
  5.         r = 1
  6.         alpha = QR.random_element()
  7.         phi = QR(x) - alpha
  8.         g = alpha ** q
  9.         while g!= alpha:
  10.             r += 1
  11.             phi *= (QR(x) - g)
  12.             g = g ** q
  13.         if r < n:
  14.             continue
  15.         phi = F(phi.list()) + f_x
  16.         print("Generated polynomial: {}" . format(phi))
  17.         return phi
  18.  
  19.  
  20. def testBenOra(F, q, f_x, x):
  21.     g = x
  22.     n = f_x.degree()
  23.     for i in range(0, int(n/2)):
  24.         g = F(pow(g, q, f_x))
  25.         if F.gcd(f_x, g - x) != 1:
  26.             return False
  27.     return True
  28.  
  29.  
  30. def main():
  31.     q = 2690663
  32.     F = PolynomialRing(GF(q), 'x')
  33.     f_x1 = F(x ** 18 + 2690564 * x ** 17 + 4590 * x ** 16 + 2558471 * x ** 15 + \
  34.         2643840 * x ** 14 + 1495497 * x ** 13 + 2554912 * x ** 12 + 1163580 * x ** 11 + \
  35.         392361 * x ** 10 + 728858 * x ** 9 + 1681172 * x ** 8 + 245680 * x ** 7 + \
  36.         723405 * x ** 5 + 1512258 * x ** 4 + 137509 * x ** 3 + 1139068 * x ** 2 + \
  37.         1685603 * x + 402025)  # Вариант 2 из ЛР4
  38.     f_x2 = F(969823 + 957345 * x + 682546 * x ** 2 + 2109839 * x ** 3 + 614684 * x ** 4 + 379226 * x ** 5
  39.        + 2118796 * x ** 6 + 660413 * x ** 7 + 2666566 * x ** 8 + 1855807 * x ** 9 + 2562208 * x ** 10
  40.        + 2325361 * x ** 11 + 1612400 * x ** 12 + 846977 * x ** 13 + 1448900 * x ** 14 + 644655 * x ** 15
  41.        + 917775 * x ** 16 + x ** 17) # ЛР 3
  42.     f_x = generate_polynomial(F, q, f_x1)
  43.     if testBenOra(F, q, f_x, f_x.variables()[0]):
  44.         print("Polynomial is irreducible according to BenOra")
  45.     else:
  46.         print("Polynomial is reducible according to BenOra")
  47.     if f_x.is_irreducible():
  48.         print("Polynomial is irreducible according to Sage")
  49.     else:
  50.         print("Polynomial is reducible according to Sage")
  51.  
  52. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement