numpy.poly1d的除法不适用于长时间多项式

时间:2019-04-14 20:38:21

标签: python numpy cryptography algebra polynomial-math

我正在编写一个程序来加密和加密Fire(希望我写出他的第二个名字正确)代码。 在查找综合症多项式的步骤中,我使用numpy的poly1d类对长多项式(19437度)进行除法,但这是行不通的。也许这是我的错,或者这门课长期无法完成。 我将对此有所帮助:也许我可以通过任何其他方法来做到这一点?

import numpy as np
import random


def main():

    polynome_second = np.poly1d
    file_code = open('code.txt', 'w')
    np.random.seed()
    for i in range(19437):
        file_code.write(str(random.randint(0, 1)))      # creating a long code
    file_code.close()
    file_code = open('code.txt', 'r')
    code_of_string = file_code.read()       
    polynomial_first = np.poly1d([int(code_of_string[i]) for i in range(code_of_string.__len__())])
    coeffs_for_forming_polynomial = []

    for i in range(30):             # creating forming polynomial: p(x) = x^29 + x^22 + x^19 - x^10 - x^3 - 1 
        if i == 29 or i == 22 or i == 19:
            coeffs_for_forming_polynomial.append(-1)
        elif i == 10 or i == 3 or i == 0:
            coeffs_for_forming_polynomial.append(1)
        else:
            coeffs_for_forming_polynomial.append(0)

    forming_polynomial = np.poly1d(coeffs_for_forming_polynomial)
    print(forming_polynomial)
    # syndrome_polynomial = np.poly1d(1)

    syndrome_polynomial = polynomial_first / forming_polynomial     #
    print(syndrome_polynomial)
    # print(isinstance(syndrome_polynomial, np.poly1d))
    # print(polynomial_first)
    file_code.close()
    return


main()

这是IDE错误的输出:

C:\Program Files\Python37\lib\site-packages\numpy\lib\polynomial.py:970: RuntimeWarning: overflow encountered in subtract
  r[k:k+n+1] -= d*v
C:\Program Files\Python37\lib\site-packages\numpy\lib\polynomial.py:970: RuntimeWarning: invalid value encountered in multiply
  r[k:k+n+1] -= d*v
C:\Program Files\Python37\lib\site-packages\numpy\lib\polynomial.py:970: RuntimeWarning: invalid value encountered in subtract
  r[k:k+n+1] -= d*v

0 个答案:

没有答案