首页 文章

使用Maple实现Fermat攻击

提问于
浏览
0

我正在尝试用枫树实施费马攻击,但它给了我一个错误,说明 Error,unexpected . 与Maple的超级初学者,所以如果有任何经验的人可以提供帮助,我将非常感激 .

另外,我试图计算一个长度为125位的整数 . 有没有人知道Maple中的任何有效算法或任何其他可以处理和计算如此大整数的程序?

FermatAtttack:=proc(n::And(posint,odd), maxnumsteps::posint:=10^7,(numsteps::truefalse:=false))
local x, k, r, i, y:
x:=isqrt(n);
if x^2 < n then
  x:= x+1
end if;
k:=2*x+1;
r:=x^2-n;
for i to maxnumsteps while not issqr(r) do
  r:=r+k;
  k:=k+2
end do;
if issqr(r) then
  x:=(k-1)/2;
  y:=isqrt(r)
else
  error "%1 could not facot in %2 iteratioons", n, maxnumsteps
end if;
if not numsteps then
  x-y, x+y
else
  x-y, x+y, i
end if;
end proc:

3 回答

  • 0

    您需要使用Number Field Sieve来计算125位整数 . 请参阅this guide开始使用 .

  • 0

    错误消息是一个简单的语法错误 . 你的第一行可能应该是

    FermatAtttack:=proc(n::And(posint,odd), maxnumsteps::posint:=10^7,{numsteps::truefalse:=false})
    

    Maple使用命令“ifactor”来计算整数 .

  • 0

    在您的过程 FermatAttack 的定义的参数序列中,您在括号参数声明中有一个圆括号项,并且您的错误消息是由此引起的 .

    (numsteps::truefalse:=false)
    

    将其更改为just,

    numsteps::truefalse:=false
    

    或者,

    {numsteps::truefalse:=false}
    

    根据你打算怎么称呼它 . 第二个被称为关键字参数 . 以下是差异的简短说明 .

    FA := proc( ns::truefalse:=false )
        print(ns);
    end proc:
    
    FA();
                                     false
    
    FA(true);
                                     true
    
    FB := proc( {ns::truefalse:=false} )
        print(ns);                        
    end proc:                           
    
    FB(); # getting the default value
                                     false
    
    FB( ns=false );
                                     false
    
    FB( ns=true );
                                     true
    
    FB( ns ); # a convenience of type truefalse keyword parameters
                                     true
    

    如果使用关键字参数方法,请注意下一个示例中传递的参数 true 与关键字(因此获取其默认值)不匹配 .

    FB( true );
                                     false
    

相关问题