Crypto-sagemath常用函数
常用sagemath函数(代数系统篇)
1.同余运算
1 | R.<x> = Zmod(module)[] |
其中,x作为求解的未知数,module表示同余的模数。
1 | f = x^3 + ... //将所有式移到f右边 |
例题:
需要求解
n ≡ p ^3 + a ∗ p ^ 2 + b ∗ p (mod n)
那么在sage中写
1 | R.<p> = Zmod(moudle) |
那么p的所有满足该同余式的解就会返回出来
2.有限域
2.1 P元有限域
有限域 p7 (所有模7的完全剩余类)
1 | k1=GF(7) |
操作有限域上的元素
1 | a=k1(5) |
求解x ** 5 ≡ 2(mod7)
1 | print(k1(2).nth_root(5)) |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment
ValineDisqus