离散对数表的绘制

q为素数,绘制1~(q-1)之间的离散对数表

代码

import pandas as pd

def fast_power(base, power, MOD):
    result = 1
    while power > 0:
        # If power is odd
        if power % 2 == 1:
            result = (result * base) % MOD

        # Divide the power by 2
        power = power // 2
        # Multiply base to itself
        base = (base * base) % MOD
    return result

q =29
df = pd.DataFrame(columns = ['a^'+str(s) for s in range(1, q)])

for i in range(1, q):
	row = []
	for j in range(1, q):
		row.append(fast_power(i, j, q))
	df.loc[i] = row

# print(df)
df.to_csv("./q_"+str(q)+".csv")

效果

q设为11,保存到本地文件q_11.csv:

posted @ 2020-12-04 13:00  爱吃砂糖橘的白龙  阅读(588)  评论(0编辑  收藏  举报