GF(2)[x] 上的8次不可约多项式求解

本文回顾了如何通过编程实现对GF(2^8)中8次多项式的暴力搜索,寻找不可约多项式,以便于在该有限域上进行密码算法操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GF(2)[x]  指系数为 0、1 的多项式。之前在学校有做过有限域 GF(2^8) 上的密码算法研究,而构成有限域 GF(2^8) 的其中一个必要条件就是选取一个 GF(2)[x] 上的8次不可约多项式(使得有限域上的加减乘除和求逆在 mod 这个不可约多项式后能正常运算),下面是当时暴力求解的代码,于是记录一下。

import numpy
import math

C = []
for i in range(1, 5):  # [1 2 3 4]
    j = 8 - i
    A = []
    B = []
    for row in range(1, int(math.pow(2, i)) + 1):  # 从1取到2^i
        tempList = []
        for x in list((bin(row))[2:].zfill(i + 1)):
            tempList.append(int(x))
        tempList[0] = 1  # i 次多项式最高次系数必须为1
        A.append(tempList)
    for row in range(1, int(math.pow(2, j)) + 1):  # 从1取到2^j
        tempList = []
        for x in list((bin(row))[2:].zfill(j + 1)):
            tempList.append(int(x))
        tempList[0] = 1
        B.append(tempList)
    for i1 in range(int(math.pow(2, i))):
        for j1 in range(int(math.pow(2, j))):
            p1 = numpy.poly1d(A[i1])  # 将系数列表传入,生成多项式
            p2 = numpy.poly1d(B[j1])
            tempCoeffs = (p1 * p2).coeffs
            for x in range(len(tempCoeffs)):
                tempCoeffs[x] = tempCoeffs[x] % 2  # 系数归一化
            C.append(tempCoeffs)  # 可分解成多项式乘积的多项式为可约多项式

for x in range(len(C)):
    C[x] = list(C[x])  # 转换成常规列表
for num in range(256):  # 0-255
    tempList = [1]
    for x in list((bin(num))[2:].zfill(8)):
        tempList.append(int(x))
    if tempList not in C:  # 如果没在可约多项式集合,则属于不可约多项式
        print(tempList)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值