使用SageMath在Python中对非常大的整数进行除法

时间:2019-10-31 11:36:32

标签: python math

我正在使用Python和SageMath实现Wiener的指数攻击。

我的代码如下

from sage.all import *
# constants
b = some_very_large_number
n = some_very_large_number
b_over_n = continued_fraction(b/n)

while True:
    t_over_a = b_over_n.convergent(i+1)
    t = t_over_a.numerator()
    a = t_over_a.denominator()
    # check if t divides ab-1
    if ((t != 0) and (gcd(a*b-1, t)== t)):
        print("Found i: ", i)
        break
    i += 1

我发现循环不会永远结束,因此在while循环之前添加了这一行代码。

print(b_over_n.convergent(5))

我发现b_over_n总是返回0,无论如何。 我还打印了type(b_over_n),并检查它是否为'long'类型。

我检查了SageMath手册,但还没有发现有用的东西。

我在这里做错什么了吗?

1 个答案:

答案 0 :(得分:0)

事实证明,我使用的是Python2,其中int/int返回int。 因此,由于在我的情况下b小于n,因此b/n自动返回了0