In [78]:
to_check=[5, 7, 
          0b10000001001, 0b10000001111, 
          0x18005, 0x11021, 0x1C867, 
          0x104c11db7, 0x11EDC6F41, 0x1741B8CD7, 0x132583499, 0x1814141AB, 
          0x100000000000000000000000000000087]
In [79]:
def chk(p):
    k.<a> = GF(2^129)
    x=k.fetch_int(p)
    y=x.polynomial()
    return (hex(p), y.is_irreducible())
In [80]:
list(map(chk, to_check))
Out[80]:
[('0x5', False),
 ('0x7', True),
 ('0x409', True),
 ('0x40f', True),
 ('0x18005', False),
 ('0x11021', False),
 ('0x1c867', True),
 ('0x104c11db7', True),
 ('0x11edc6f41', False),
 ('0x1741b8cd7', False),
 ('0x132583499', False),
 ('0x1814141ab', False),
 ('0x100000000000000000000000000000087', True)]
In [81]:
def factor_poly(p):
    k.<a> = GF(2^129)
    x=k.fetch_int(p)
    y=x.polynomial()
    print ("input poly:", y)
    if y.is_irreducible():
        print ("prime")
    else:
        print (y.factor())
In [82]:
factor_poly(0x18005)
input poly: a^16 + a^15 + a^2 + 1
(a + 1) * (a^15 + a + 1)
In [83]:
factor_poly(0x142F0E1EBA9EA3693)
input poly: a^64 + a^62 + a^57 + a^55 + a^54 + a^53 + a^52 + a^47 + a^46 + a^45 + a^40 + a^39 + a^38 + a^37 + a^35 + a^33 + a^32 + a^31 + a^29 + a^27 + a^24 + a^23 + a^22 + a^21 + a^19 + a^17 + a^13 + a^12 + a^10 + a^9 + a^7 + a^4 + a + 1
(a + 1)^2 * (a^15 + a + 1) * (a^15 + a^10 + a^5 + a + 1) * (a^15 + a^12 + a^3 + a + 1) * (a^17 + a^14 + a^12 + a^11 + a^10 + a^9 + a^8 + a^5 + a^4 + a^3 + 1)
In [84]:
factor_poly(0x100000000000000000000000000000087)
input poly: a^128 + a^7 + a^2 + a + 1
prime
In [85]:
factor_poly(0x132583499)
input poly: a^32 + a^29 + a^28 + a^25 + a^22 + a^20 + a^19 + a^13 + a^12 + a^10 + a^7 + a^4 + a^3 + 1
(a + 1)^2 * (a^30 + a^28 + a^27 + a^25 + a^20 + a^17 + a^15 + a^13 + a^10 + a^5 + a^3 + a^2 + 1)
In [86]:
factor_poly(0x11021)
input poly: a^16 + a^12 + a^5 + 1
(a + 1) * (a^15 + a^14 + a^13 + a^12 + a^4 + a^3 + a^2 + a + 1)
In [87]:
factor_poly(0x39)
input poly: a^5 + a^4 + a^3 + 1
(a + 1)^2 * (a^3 + a^2 + 1)