Board logo

標題: 用Maxima學密碼學-橢圓曲線離散對數問題 [打印本頁]

作者: bugmens    時間: 2020-3-29 22:16     標題: 用Maxima學密碼學-橢圓曲線離散對數問題

離散對數問題(Discrete Logarithm Problem,DLP)
已知\(\alpha,\beta,p\),\(0<\alpha,\beta<p\),\(GCD(\alpha,p)=1\),\(\alpha^x\equiv \beta \pmod{p}\),當\(p\)很大時,計算\(x\)值非常困難。

橢圓曲線離散對數問題(Elliptic Curve Discrete Logarithm Problem,ECDLP)
(1)令\(E\)為基於有限體\(F_p\)的橢圓曲線,\(P,Q\)為橢圓曲線上的點坐標(\(P,Q\in E(F_p)\))且\(Q=kP,k\in N\),當\(p\)很大時,計算\(k\)值非常困難。
(2)令\(E\)為基於二元體\(F_{2^n}\)的橢圓曲線,\(P,Q\)為橢圓曲線上的點坐標(\(P,Q\in E(F_{2^n})\))且\(Q=kP,k\in N\),當\(n\)很大時,計算\(k\)值非常困難。
以下介紹解離散對數問題和橢圓曲線離散對數問題的各種方法。
作者: bugmens    時間: 2020-4-3 07:41

1.解離散對數問題的方法-小步大步(Baby-step Giant-step)

將答案改寫成\(x=im+j\),其中\(m=\lceil\;\sqrt{p}\rceil\;\),\(0\le i<m\),\(0\le j<m\)
將原本離散對數問題改成
\(\alpha^x \equiv \beta \pmod{p}\)
\(\alpha^{im+j}\equiv \beta \pmod{p}\)
\(\alpha^j\equiv \beta(\alpha^{-m})^i \pmod{p}\)
計算\(\alpha^j\)稱為Baby-step
計算\(\beta(\alpha^{-m})^i\)稱為Giant-step
當某個\(i\)和\(j\)值讓\(\alpha^j\)和\(\beta(\alpha^{-m})^i\)相等時,就代表找到答案\(x=im+j\)

虛擬碼
1.\(m=Ceiling(\sqrt{p})\)
2.for j=0~m-1
 計算\([\alpha^j\pmod{p},j]\)數對放在List中
3.計算\(\alpha^{-m}\)
4.設\(\gamma=\beta\)
5.for i=0~m-1
 檢查目前\(\gamma\)值是否等於List中某個\(\alpha^j\pmod{p}\)
 若是,答案\(x=im+j\)
 若否,計算\(\gamma=\gamma \cdot \alpha^{-m}\)

參考資料:https://en.wikipedia.org/wiki/Baby-step_giant-step



Baby_stepGiant_step副程式
(%i1)
Baby_stepGiant_step(alpha,beta,p):=block
([m,gamma,List,inv_am,i,j,Powerj,x:[]],
print("取Giant步長m=Ceiling(",sqrt(p),")=",m:ceiling(sqrt(p))),
print("Baby step,計算",alpha^"0",",",alpha^"1",",...,",alpha,""^(m-1),"(mod ",p,")"),
print("List=",List:create_list(power_mod(alpha,j,p),j,0,m-1)),
print("(",a^"-1",")"^m,"≡(",alpha^"-1",")"^m,"≡",inv_mod(alpha,p),""^m,"≡",inv_am:power_mod(alpha,-m,p),"(mod ",p,")"),
print("令γ=β=",gamma:beta),
print("Giant step,每次γ值再乘上(α"^"-1",")"^m),
for i:0 thru m-1 do
  (print("當i=",i,"時"),
   Powerj:sublist_indices(List,lambda([aj],aj=gamma))-1,/*檢查List中是否有gamma值*/
   if Powerj#[] then
      (print("List中有γ=",gamma,"值"),
       for j in Powerj do
         (print("j=",j,"次方,找到一解x=i*m+j=",i,"*",m,"+",j,"=",last(x:append(x,[i*m+j])))
         )
      )
  else
      (print("List中沒有γ=",gamma,"值")
      ),
  print("計算γ≡γ*(α"^"-1",")"^m,"≡",gamma,"*",inv_am,"≡",gamma*inv_am,"≡",gamma:mod(gamma*inv_am,p),"(mod ",p,")")
      
  ),
return(x)
)$


\(\alpha^x \equiv \beta\pmod{p}\),\(x=\)?
(%i4)
alpha:2;
beta:108;
p:181;

(alpha) 2
(beta) 108
(p) 181

利用Baby_stepGiant_step方法解離散對數問題
(%i5) x:Baby_stepGiant_step(alpha,beta,p);
取Giant步長\(m=Ceiling(\sqrt{181})=14\)
Babystep,計算\(2^0,2^1,\ldots,2^{13}\pmod{181}\)
\(List=[1,2,4,8,16,32,64,128,75,150,119,57,114,47]\)
\((\alpha^{-1})^{14}\equiv(2^{-1})^{14}\equiv91^{14}\equiv52\pmod{181}\)
令\(\gamma=\beta=108\)
Giantstep,每次\(\gamma\)值再乘上\((\alpha^{-1})^{14}\)
當\(i=0\)時
List中沒有\(\gamma=108\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv108*52\equiv5616\equiv5\pmod{181}\)
當\(i=1\)時
List中沒有\(\gamma=5\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv5*52\equiv260\equiv79\pmod{181}\)
當\(i=2\)時
List中沒有\(\gamma=79\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv79*52\equiv4108\equiv126\pmod{181}\)
當\(i=3\)時
List中沒有\(\gamma=126\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv126*52\equiv6552\equiv36\pmod{181}\)
當\(i=4\)時
List中沒有\(\gamma=36\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv36*52\equiv1872\equiv62\pmod{181}\)
當\(i=5\)時
List中沒有\(\gamma=62\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv62*52\equiv3224\equiv147\pmod{181}\)
當\(i=6\)時
List中沒有\(\gamma=147\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv147*52\equiv7644\equiv42\pmod{181}\)
當\(i=7\)時
List中沒有\(\gamma=42\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv42*52\equiv2184\equiv12\pmod{181}\)
當\(i=8\)時
List中沒有\(\gamma=12\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv12*52\equiv624\equiv81\pmod{181}\)
當\(i=9\)時
List中沒有\(\gamma=81\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv81*52\equiv4212\equiv49\pmod{181}\)
當\(i=10\)時
List中沒有\(\gamma=49\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv49*52\equiv2548\equiv14\pmod{181}\)
當\(i=11\)時
List中沒有\(\gamma=14\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv14*52\equiv728\equiv4\pmod{181}\)
當\(i=12\)時
List中有\(\gamma=4\)值
j=2次方,找到一解\(x=i*m+j=12*14+2=170\)
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv4*52\equiv208\equiv27\pmod{181}\)
當\(i=13\)時
List中沒有\(\gamma=27\)值
計算\(\gamma\equiv\gamma*(\alpha^{-1})^{14}\equiv27*52\equiv1404\equiv137\pmod{181}\)
(x) \([170]\)
作者: bugmens    時間: 2020-4-5 22:03

2.解離散對數問題的方法-小步大步(Baby-step giant-step)

相同原理提供另一種實作
虛擬碼
1.\(m=Ceiling(\sqrt{p})\)
2.計算\(\alpha^{-m}\)
3.for j=0~m-1
 計算\([\alpha^j \pmod{p},j]\)數對放在BabyStep List中
4.for i=0~m-1
 計算\([\beta(\alpha^{-m})^i \pmod{p},i]\)數對放在GiantStep List中
5.將BabyStep和GiantStep的List由小到大重新排序
6.兩個List互相比較找出相同值
 若有,答案\(x=im+j\)
 若沒有,答案無解

參考資料:Computational Number Theory and Modern Cryptography



Baby_stepGiant_step副程式
(%i1)
Baby_stepGiant_step(alpha,beta,p):=block
([m,inv_am,BabyStep,GiantStep,indexB:1,indexG:1,i,j,x:[]],
print("取Giant步長m=Ceiling(",sqrt(p),")=",m:ceiling(sqrt(p))),
print("(",a^"-1",")"^m,"≡(",alpha^"-1",")"^m,"≡",inv_mod(alpha,p),""^m,"≡",inv_am:power_mod(alpha,-m,p),"(mod ",p,")"),
print("BabyStep=",BabyStep:create_list([power_mod(alpha,j,p),j],j,0,m-1)),
print("GiantStep=",GiantStep:create_list([mod(beta*power_mod(inv_am,i,p),p),i],i,0,m-1)),
print("由小到大排序"),
print("BabyStep=",BabyStep:sort(BabyStep)),
print("GiantStep=",GiantStep:sort(GiantStep)),
print("BabyStep和GiantStep互相比較找出相同值"),
print("一開始indexB=1,indexG=1"),
while indexB<=m and indexG<=m do
   (if BabyStep[indexB][1]=GiantStep[indexG][1] then
      (do
          (i:GiantStep[indexG][2],j:BabyStep[indexB][2],/*第2個值是i和j*/
           print("BabyStep[",indexB,"]=",BabyStep[indexB],"第1個值等於",
                   "GiantStep[",indexG,"]=",GiantStep[indexG],"第1個值,得到一解x=i*m+j=",i,"*",m,"+",j,"=",last(x:append(x,[i*m+j]))),
           print("GiantStep移到下一組,indexG=indexG+1=",indexG:indexG+1),
           if indexG=m or GiantStep[indexG][1]#GiantStep[indexG-1][1] then
              (return())
          ),
        print("BabyStep移到下一組,indexB=indexB+1=",indexB:indexB+1)
      )
    else if BabyStep[indexB][1]<GiantStep[indexG][1] then
      (print("BabyStep[",indexB,"]=",BabyStep[indexB],"第1個值小於",
               "GiantStep[",indexG,"]=",GiantStep[indexG],"第1個值,BabyStep移到下一組,indexB=indexB+1=",indexB:indexB+1)
      )
    else
      (print("BabyStep[",indexB,"]=",BabyStep[indexB],"第1個值大於",
               "GiantStep[",indexG,"]=",GiantStep[indexG],"第1個值,GiantStep移到下一組,indexG=indexG+1=",indexG:indexG+1)
      )
   ),
return(x)
)$


\(\alpha^x \equiv \beta \pmod{p}\),\(x=\)?
(%i4)
alpha:2;
beta:108;
p:181;

(alpha) 2
(beta) 108
(p) 181

利用Baby_stepGiant_step方法解離散對數問題
(%i5) Baby_stepGiant_step(alpha,beta,p);
取Giant步長\(m=Ceiling(\sqrt{181})=14\)
\((a^{-1})^{14}\equiv(2^{-1})^{14}\equiv 91^{14}\equiv52\pmod{181}\)
\(BabyStep=[[1,0],[2,1],[4,2],[8,3],[16,4],[32,5],[64,6],[128,7],[75,8],[150,9],[119,10],[57,11],[114,12],[47,13]]\)
\(GiantStep=[[108,0],[5,1],[79,2],[126,3],[36,4],[62,5],[147,6],[42,7],[12,8],[81,9],[49,10],[14,11],[4,12],[27,13]]\)
由小到大排序
\(BabyStep=[[1,0],[2,1],[4,2],[8,3],[16,4],[32,5],[47,13],[57,11],[64,6],[75,8],[114,12],[119,10],[128,7],[150,9]]\)
\(GiantStep=[[4,12],[5,1],[12,8],[14,11],[27,13],[36,4],[42,7],[49,10],[62,5],[79,2],[81,9],[108,0],[126,3],[147,6]]\)
BabyStep和GiantStep互相比較找出相同值
一開始\(indexB=1,indexG=1\)
\(BabyStep[1]=[1,0]\)第1個值小於\(GiantStep[1]=[4,12]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=2\)
\(BabyStep[2]=[2,1]\)第1個值小於\(GiantStep[1]=[4,12]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=3\)
\(BabyStep[3]=[4,2]\)第1個值等於\(GiantStep[1]=[4,12]\)第1個值,得到一解\(x=i*m+j=12*14+2=170\)
GiantStep移到下一組,\(indexG=indexG+1=2\)
BabyStep移到下一組,\(indexB=indexB+1=4\)
\(BabyStep[4]=[8,3]\)第1個值大於\(GiantStep[2]=[5,1]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=3\)
\(BabyStep[4]=[8,3]\)第1個值小於\(GiantStep[3]=[12,8]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=5\)
\(BabyStep[5]=[16,4]\)第1個值大於\(GiantStep[3]=[12,8]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=4\)
\(BabyStep[5]=[16,4]\)第1個值大於\(GiantStep[4]=[14,11]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=5\)
\(BabyStep[5]=[16,4]\)第1個值小於\(GiantStep[5]=[27,13]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=6\)
\(BabyStep[6]=[32,5]\)第1個值大於\(GiantStep[5]=[27,13]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=6\)
\(BabyStep[6]=[32,5]\)第1個值小於\(GiantStep[6]=[36,4]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=7\)
\(BabyStep[7]=[47,13]\)第1個值大於\(GiantStep[6]=[36,4]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=7\)
\(BabyStep[7]=[47,13]\)第1個值大於\(GiantStep[7]=[42,7]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=8\)
\(BabyStep[7]=[47,13]\)第1個值小於\(GiantStep[8]=[49,10]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=8\)
\(BabyStep[8]=[57,11]\)第1個值大於\(GiantStep[8]=[49,10]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=9\)
\(BabyStep[8]=[57,11]\)第1個值小於\(GiantStep[9]=[62,5]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=9\)
\(BabyStep[9]=[64,6]\)第1個值大於\(GiantStep[9]=[62,5]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=10\)
\(BabyStep[9]=[64,6]\)第1個值小於\(GiantStep[10]=[79,2]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=10\)
\(BabyStep[10]=[75,8]\)第1個值小於\(GiantStep[10]=[79,2]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=11\)
\(BabyStep[11]=[114,12]\)第1個值大於\(GiantStep[10]=[79,2]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=11\)
\(BabyStep[11]=[114,12]\)第1個值大於\(GiantStep[11]=[81,9]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=12\)
\(BabyStep[11]=[114,12]\)第1個值大於\(GiantStep[12]=[108,0]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=13\)
\(BabyStep[11]=[114,12]\)第1個值小於\(GiantStep[13]=[126,3]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=12\)
\(BabyStep[12]=[119,10]\)第1個值小於\(GiantStep[13]=[126,3]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=13\)
\(BabyStep[13]=[128,7]\)第1個值大於\(GiantStep[13]=[126,3]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=14\)
\(BabyStep[13]=[128,7]\)第1個值小於\(GiantStep[14]=[147,6]\)第1個值,BabyStep移到下一組,\(indexB=indexB+1=14\)
\(BabyStep[14]=[150,9]\)第1個值大於\(GiantStep[14]=[147,6]\)第1個值,GiantStep移到下一組,\(indexG=indexG+1=15\)
(%o5) \([170]\)
作者: bugmens    時間: 2020-7-25 10:22

3-1.解離散對數問題的方法-小步和倍增步長的大步(Baby-step and double step width Giant-step)


原本的小步大步小步和倍增步長的大步
將答案改寫成\(x=im+j\)
其中\(m=\lceil\;\sqrt{p}\rceil\;\),\(0\le i<m\),\(0\le j<m\)

\(\alpha^x \equiv \beta \pmod{p}\)
\(\alpha^{im+j}\equiv \beta \pmod{p}\)
\(\alpha^j \equiv \beta(\alpha^{-m})^i \pmod{p}\)
計算\(\alpha^j\)稱為Baby step
計算\(\beta(\alpha^{-m})^i\)稱為Giant step
每次步長都是\(\alpha^{-m}\)
將答案改寫成\(x=2^kvq+r\) (\(x\)除以\(2^kv\),商數\(q\),餘數\(r\))
其中\(v\)為偶數,\(k\ge 0\),\(1\le r \le 2^kv\)

\(\alpha^x \equiv \beta \pmod{p}\)
\(\displaystyle \alpha^{2^kvq+r}\equiv \beta \pmod{p}\)
\(\displaystyle \beta \alpha^{-r}\equiv (\alpha^{2^kv})^q \pmod{p}\)
計算\( \beta\alpha^{-r}\)稱為Baby step
計算\((\alpha^{2^kv})^q\)稱為Giant step
每次步長\(\alpha^{2^kv}\)隨著\(k\)值倍增


Lemma 2.1 設\(v\)為正偶數,對每一個正整數\(x\),存在唯一的\(k \ge 0\),\(q\)和\(r\),\(\lfloor\;4^{k-1}\rfloor\;v^2\le 2^kvq <4^kv^2\)和\(1\le r\le 2^kv\),使得\(x=y+r\),\(y=2^kvq\)。

以\(2^x \equiv 108 \pmod{181}\),參數\(v=2\)為例。
--------
當\(k=0\)時
\(BabyStep\):\(1\le r \le 2^0v\),\(1\le r \le 2\),\(r=1,2\)
\(GiantStep\):\(\lfloor\;4^{-1}\rfloor\;v^2\le 2^kvq<4^0v^2\),\(0\le 2^kvq<4\),\(2^kvq=0,2\),倍增步長為2
可能\(x=1,2,3,4\)
--------
當\(k=1\)時
\(BabyStep\):\(1\le r \le 2^1v\),\(1\le r \le 4\),\(r=1,2,3,4\)
\(GiantStep\):\(\lfloor\;4^0\rfloor\;v^2\le 2^kvq<4^1v^2\),\(4\le 2^kvq<16\),\(2^kvq=4,8,12\),倍增步長為4
可能\(x=5,6,\ldots,16\)
--------
當\(k=2\)時
\(BabyStep\):\(1\le r \le 2^2v\),\(1\le r \le 8\),\(r=1,2,3,4,5,6,7,8\)
\(GiantStep\):\(\lfloor\;4^1\rfloor\;v^2\le 2^kvq<4^2v^2\),\(16\le 2^kvq<64\),\(2^kvq=16,24,32,40,48,56\),倍增步長為8
可能\(x=17,18,\ldots,64\)
--------
當\(k=3\)時
\(BabyStep\):\(1\le r \le 2^3v\),\(1\le r \le 16\),\(r=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16\)
\(GiantStep\):\(\lfloor\;4^2\rfloor\;v^2\le 2^kvq<4^3v^2\),\(64\le 2^kvq<256\),\(2^kvq=64,80,96,112,128,144,160,176,192,208,224,240\),倍增步長為16
可能\(x=65,66,\ldots,256\),已經超過全部可能答案\(x=1,2,\ldots,181\)

參考資料:https://www.ams.org/journals/mco ... 5718-97-00880-6.pdf



Baby_stepDoubleGiant_step副程式
(%i1)
Baby_stepDoubleGiant_step(alpha,beta,p,v):=block
([k:0,BabyStep,GiantStep,GiantPower,indexB:1,indexG:1,LengthB,LengthG,x:[]],
if primep(p)=false then
  (print("參數p=",p,"要是質數"),
   return()
  ),
if mod(v,2)=1 then
  (print("參數v=",v,"要是偶數"),
   return()
  ),
do
  (print("當k=",k,"時"),
   print("1≦r≦",2^"k","v,1≦r≦",2^k*v),
   print(alpha^"-1","=",inv_mod(alpha,p),"(mod",p,")"),
   print("BabyStep=[",beta,"*",alpha^"-r","(mod",p,"),",r,"]=",
            BabyStep:create_list([mod(beta*power_mod(alpha,-r,p),p),r],r,1,2^k*v)),
   print("floor(",4^"k-1",")v"^"2","≦",2^"k","vq<",4^"k","v"^2,",",floor(4^(k-1))*v^2,"≦",2^"k","vq<",4^k*v^2),
   print(2^"k","vq=",GiantPower:create_list(2^k*v*q,q,floor(4^(k-1))/2^k*v,2^k*v-1),
          ",倍增步長為",2^k*v),
   print("GiantStep=[",alpha^(2^"k"*"v"*q),"(mod",p,")",",",2^"k"*"v"*q,"]=",
            GiantStep:map(lambda([power],[power_mod(alpha,power,p),power]),GiantPower)),
   print("由小到大排序"),
   print("BabyStep=",BabyStep:sort(BabyStep)),
   print("GiantStep=",GiantStep:sort(GiantStep)),
   print("BabyStep和GiantStep互相比較找出相同值"),
   LengthB:length(BabyStep),
   LengthG:length(GiantStep),
   while indexB<=LengthB and indexG<=LengthG do
     (if BabyStep[indexB][1]=GiantStep[indexG][1] then
        (do
            (print("BabyStep[",indexB,"]=",BabyStep[indexB],"和","GiantStep[",indexG,"]=",GiantStep[indexG],"的第一個值相同"),
             print("得到一解x=",BabyStep[indexB][2],"+",GiantStep[indexG][2],
                   "=",last(x:append(x,[BabyStep[indexB][2]+GiantStep[indexG][2]]))),
             indexG:indexG+1,
             if indexG>LengthG or GiantStep[indexG][1]#GiantStep[indexG-1][1] then
               (return())
            ),
         indexB:indexB+1
        )
      else if BabyStep[indexB][1]<GiantStep[indexG][1] then
        (indexB:indexB+1)
      else
        (indexG:indexG+1)
     ),
   if x=[] then/*沒找到解答*/
     (print("BabyStep和GiantStep沒有相同值"))
   else/*找到解答跳出去*/
     (print("將x=",x,"(mod",p-1,")=",x:mod(x,p-1)),
      print("再刪除相同值x=",x:unique(x)),
      return(x)
     ),
   if 4^k*v^2>p then
     (print("無解"),
      return()
     ),
   k:k+1,/*換下一個k值*/
   print("--------")
  )
)$


\(\alpha^x\equiv \beta \pmod{p}\),初始步長\(v\)要是偶數
(%i5)
alpha:2;
beta:108;
p:181;
v:2;

(alpha) 2
(beta) 108
(p) 181
(v) 2

利用Baby_stepDoubleGiant_step方法解離散對數問題
(%i6) x:Baby_stepDoubleGiant_step(alpha,beta,p,v);
當\(k=0\)時
\(1\le r\le 2^k v\),\(1\le r\le 2\)
\(2^{-1} \equiv 91 \pmod{181}\)
\(BabyStep=[ 108 * 2^{-r} \pmod{181}, r ]= [[54,1],[27,2]]\)
\(floor( 4^{k-1} )v^2 \le 2^k vq< 4^k v^2\),\(0 \le 2^k vq< 4\)
\(2^k vq= [0,2]\),倍增步長為 2
\(GiantStep=[ 2^{2^kvq} \pmod{181},2^kvq]=[[1,0],[4,2]]\)
由小到大排序
\(BabyStep= [[27,2],[54,1]]\)
\(GiantStep= [[1,0],[4,2]]\)
\(BabyStep\)和\(GiantStep\)互相比較找出相同值
\(BabyStep\)和\(GiantStep\)沒有相同值
--------
當\(k=1\)時
\(1\le r\le 2^k v\),\(1\le r\le 4\)
\(2^{-1} \equiv 91 \pmod{181}\)
\(BabyStep=[ 108 * 2^{-r}\pmod{181},r]=[[54,1],[27,2],[104,3],[52,4]]\)
\(floor( 4^{k-1})v^2 \le 2^k vq< 4^k v^2\),\(4\le 2^k vq< 16\)
\(2^k vq= [4,8,12]\),倍增步長為 4
\(GiantStep=[ 2^{2^kvq} \pmod{181},2^kvq]=[[16,4],[75,8],[114,12]]\)
由小到大排序
\(BabyStep=[[27,2],[52,4],[54,1],[104,3]]\)
\(GiantStep=[[16,4],[75,8],[114,12]]\)
\(BabyStep\)和\(GiantStep\)互相比較找出相同值
\(BabyStep\)和\(GiantStep\)沒有相同值
--------
當\(k=2\)時
\(1\le r\le 2^k v\),\(1\le r\le 8\)
\(2^{-1}\equiv 91 \pmod{181}\)
\(BabyStep=[ 108 * 2^{-r} \pmod{181},r]=[[54,1],[27,2],[104,3],[52,4],[26,5],[13,6],[97,7],[139,8]]\)
\(floor( 4^{k-1})v^2 \le 2^k vq< 4^k v^2\),\(16\le 2^k vq< 64\)
\(2^k vq= [16,24,32,40,48,56]\),倍增步長為 8
\(GiantStep=[ 2^{2^kvq} \pmod{181},2^kvq]=[[14,16],[145,24],[15,32],[39,40],[29,48],[3,56]]\)
由小到大排序
\(BabyStep=[[13,6],[26,5],[27,2],[52,4],[54,1],[97,7],[104,3],[139,8]]\)
\(GiantStep=[[3,56],[14,16],[15,32],[29,48],[39,40],[145,24]]\)
\(BabyStep\)和\(GiantStep\)互相比較找出相同值
\(BabyStep\)和\(GiantStep\)沒有相同值
--------
當\(k=3\)時
\(1\le r\le 2^k v\),\(1\le r\le 16\)
\(2^{-1}\equiv 91 \pmod{181}\)
\(BabyStep=[ 108 * 2^{-r} \pmod{181},r]=[[54,1],[27,2],[104,3],[52,4],[26,5],[13,6],\)
\([97,7],[139,8],[160,9],[80,10],[40,11],[20,12],[10,13],[5,14],[93,15],[137,16]]\)
\(floor( 4^{k-1})v^2 \le 2^k vq< 4^k v^2\),\(64 \le 2^k vq< 256\)
\(2^kvq=[64,80,96,112,128,144,160,176,192,208,224,240]\),倍增步長為 16
\(GiantStep=[ 2^{2^kvq} \pmod{181},2^kvq]=[[44,64],[73,80],[117,96],[9,112],\)
\([126,128],[135,144],[80,160],[34,176],[114,192],[148,208],[81,224],[48,240]]\)
由小到大排序
\(BabyStep=[[5,14],[10,13],[13,6],[20,12],[26,5],[27,2],[40,11],[52,4],[54,1],[80,10],\)
\([93,15],[97,7],[104,3],[137,16],[139,8],[160,9]]\)
\(GiantStep=[[9,112],[34,176],[44,64],[48,240],[73,80],[80,160],[81,224],[114,192],\)
\([117,96],[126,128],[135,144],[148,208]]\)
\(BabyStep\)和\(GiantStep\)互相比較找出相同值
\(BabyStep[10]=[80,10]\)和\(GiantStep[6]=[80,160]\)的第一個值相同
得到一解\(x=10+160=170\)
將\(x=[170] \pmod{180}=[170]\)
再刪除相同值\(x=[170]\)
(x) \([170]\)
作者: bugmens    時間: 2020-8-6 15:57

3-2.解離散對數問題的方法-小步和倍增步長的大步(Baby-step and double step width Giant-step)

若能理解上一篇文章,再回頭看論中的演算法2.2計算\(g\)的order。
\(g^x \equiv 1\pmod{p}\)
\(g^{y+r}\equiv 1 \pmod{p}\)
\(g^y \equiv g^{-r}\pmod{p}\)
計算\(g^{-r}\)稱為Baby step
計算\(g^y\)稱為Giant step

演算法2.2
輸入:\(g\in G\),\(|\;g|\;\)的下限\(C+1\)(若已知解答\(x\)不會在\(1\sim C\)之間),初始步長\(v\)(\(v\)要是偶數)
輸出:\(x=|\;g|\;\)
(1) \(x = 0\)
(2) \(s = 1; y = v; u = v\)
(3) \(h = g^{−1}\)
(4) \(a = h^C; b = g^v; c = b\)    /*\(a = g^{−C−r};b = g^y; c = g^u\)*/
(5) \(R=\phi;\)
(6) while (\(x == 0\)) do
(7)  for (\(r = s,s + 1\ldots, u\)) do /*new baby steps*/
(8)   \(a=a*h\)
(9)   if (\(s==1\)) then     /*check if \(1\le x\le v\)*/
(10)    if (\(a==1\)) then
(11)     \(x=r+C\)
(12)     return (\(x\))
(13)     break while
(14)    else
(15)     \(R = R\cup \{\;(a,r)\}\;\)
(16)    fi
(17)   else
(18)    \(R=R\cup \{\;(a,r)\}\;\)
(19)    fi
(20)  od
(21)  while(\(x==0\) and \(y<u^2\))do  /*giant steps*/
(22)   if(there is a number \(r\) such that \((b,r)\in R\)) then
(23)    \(x=y+r+C\)
(24)    return(\(x\))
(25)   else
(26)    \(y=y+u\)
(27)    \(b=b*c\)
(28)   fi
(29)  od
(30)  \(s=u+1;u=2u\)       /*double step-width*/
(31)  \(c=c^2\)
(32) od



計算一個元素g的Order副程式
(%i1)
Order(g,p,C,v):=block
([x,r,s,y,u,h,a,b,c,R],
print("1.變數初始化-------"),
print("x=0"),x:0,
print("s=",s:1),
print("y=v=",y:v),
print("u=v=",u:v),
print("h=g"^"-1","=",g^"-1","≡",h:inv_mod(g,p),"(mod",p,")"),
print("從",g^concat("-",C),"(mod",p,")開始計算,a=h"^"C","=",h,""^C,"≡",a:power_mod(h,C,p),"(mod",p,")"),
print("b=g"^"v","=",g,""^v,"≡",b:power_mod(g,v,p),"(mod",p,")"),
print("c=b=",c:b),
print("R=",R:[]),
while x=0 do
  (print("2.計算BabyStep-------"),
   for r:s thru u do
     (print("計算",g^concat("-",C+r),"(mod",p,")",",a=a*h=",a,"*",h,"≡",a:mod(a*h,p),"(mod",p,")"),
      if s=1 then
        (if a=1 then
           (print("解答x=r+C=",r,"+",C,"=",x:r+C),
            return(x)
           )
         else
           (R:append(R,[[a,r]]),
            print("R=R∪",[a,r])
           )
        )
      else
        (R:append(R,[[a,r]]),
         print("R=R∪",[a,r])
        )
     ),
   print("BabyStep=",R),
   print("3.計算GiantStep-------"),
   while x=0 and y<u^2 do
     (if (r:assoc(b,R))#false then
         (print("計算",g,""^y,"≡",b,"(mod",p,")在R[",r,"]=",R[r],"裡面"),
          print("解答x=y+r+C=",y,"+",r,"+",C,"=",x:y+r+C),
          return(x)
         )
      else
         (print("計算",g,""^y,"≡",b,"(mod",p,")不在R裡面"),
          print("更新次方y=y+u=",y,"+",u,"=",y:y+u),
          print("b=b*c=",b,"*",c,"≡",b:mod(b*c,p),"(mod",p,")")
         )
     ),
    print("s=u+1=",s:u+1),
    print("u=2*u=",u:2*u),
    print("倍增步長c=c"^2,"=",c:c^2)
  ),
return(x)
)$


\(g^x \equiv 1 \pmod{p}\),\(C+1\)下限,初始步長\(v\)要是偶數
(%i5)
g:2;
p:181;
C:10;
v:2;

(g) 2
(p) 181
(C) 10
(v) 2

利用Baby_stepDoubleGiant_step方法計算\(g\)的order
(%i6) x:Order(g,p,C,v);
1.變數初始化-------
\(x=0\)
\(s=1\)
\(y=v=2\)
\(u=v=2\)
\(h=g^{-1}= 2^{-1}\equiv 91\pmod{181}\)
從\(2^{-10}\pmod{181}\)開始計算,\(a=h^C = 91 ^{10} \equiv 108\pmod{181}\)
\(b=g^v = 2 ^2 \equiv 4\pmod{181}\)
\(c=b=4\)
\(R=[]\)
2.計算BabyStep-------
計算\(2^{-11}\pmod{181}\),\(a=a*h= 108 * 91 \equiv 54\pmod{181}\)
\(R=R\cup[54,1]\)
計算\(2^{-12}\pmod{181}\),\(a=a*h= 54 * 91 \equiv 27\pmod{181}\)
\(R=R\cup[27,2]\)
BabyStep=\([[54,1],[27,2]]\)
3.計算GiantStep-------
計算\(2^2 \equiv 4\pmod{181}\)不在R裡面
更新次方\(y=y+u=2+2=4\)
\(b=b*c= 4 * 4 \equiv 16\pmod{181}\)
\(s=u+1=3\)
\(u=2*u=4\)
倍增步長\(c=c^2=16\)
2.計算BabyStep-------
計算\(2^{-13}\pmod{181}\),\(a=a*h= 27 * 91 \equiv 104\pmod{181}\)
\(R=R\cup[104,3]\)
計算\(2^{-14}\pmod{181}\),\(a=a*h= 104 * 91 \equiv 52\pmod{181}\)
\(R=R\cup[52,4]\)
BabyStep=\([[54,1],[27,2],[104,3],[52,4]]\)
3.計算GiantStep-------
計算\(2^4 \equiv 16\pmod{181}\)不在R裡面
更新次方\(y=y+u=4+4=8\)
\(b=b*c= 16 * 16 \equiv 75\pmod{181}\)
計算\(2^8 \equiv 75\pmod{181}\)不在R裡面
更新次方\(y=y+u= 8 + 4 = 12\)
\(b=b*c= 75 * 16 \equiv 114\pmod{181}\)
計算\(2^{12} \equiv 114\pmod{181}\)不在R裡面
更新次方\(y=y+u=12+4=16\)
\(b=b*c= 114 * 16 \equiv 14\pmod{181}\)
\(s=u+1= 5\)
\(u=2*u= 8\)
倍增步長\(c=c^2 = 256\)
2.計算BabyStep-------
計算\(2^{-15}\pmod{181}\),\(a=a*h= 52 * 91 \equiv 26\pmod{181}\)
\(R=R\cup[26,5]\)
計算\(2^{-16}\pmod{181}\),\(a=a*h= 26 * 91 \equiv 13\pmod{181}\)
\(R=R\cup[13,6]\)
計算\(2^{-17}\pmod{181}\),\(a=a*h= 13 * 91 \equiv 97\pmod{181}\)
\(R=R\cup[97,7]\)
計算\(2^{-18}\pmod{181}\),\(a=a*h= 97 * 91 \equiv 139\pmod{181}\)
\(R=R\cup[139,8]\)
BabyStep=\([[54,1],[27,2],[104,3],[52,4],[26,5],[13,6],[97,7],[139,8]]\)
3.計算GiantStep-------
計算\(2^{16} \equiv 14\pmod{181}\)不在R裡面
更新次方\(y=y+u=16+8=24\)
\(b=b*c= 14 * 256 \equiv 145\pmod{181}\)
計算\(2^{24} \equiv 145\pmod{181}\)不在R裡面
更新次方\(y=y+u= 24 + 8 = 32\)
\(b=b*c= 145 * 256 \equiv 15\pmod{181}\)
計算\(2^{32} \equiv 15\pmod{181}\)不在R裡面
更新次方\(y=y+u= 32 + 8 = 40\)
\(b=b*c= 15 * 256 \equiv 39\pmod{181}\)
計算\(2^{40} \equiv 39\pmod{181}\)不在R裡面
更新次方\(y=y+u= 40 + 8 = 48\)
\(b=b*c= 39 * 256 \equiv 29\pmod{181}\)
計算\(2^{48} \equiv 29\pmod{181}\)不在R裡面
更新次方\(y=y+u= 48 + 8 = 56\)
\(b=b*c= 29 * 256 \equiv 3\pmod{181}\)
計算\(2^{56} \equiv 3\pmod{181}\)不在R裡面
更新次方\(y=y+u= 56 + 8 = 64\)
\(b=b*c= 3 * 256 \equiv 44\pmod{181}\)
\(s=u+1= 9\)
\(u=2*u= 16\)
倍增步長\(c=c^2 = 65536\)
2.計算BabyStep-------
計算\(2^{-19}\pmod{181}\),\(a=a*h= 139 * 91 \equiv 160\pmod{181}\)
\(R=R\cup[160,9]\)
計算\(2^{-20}\pmod{181}\),\(a=a*h= 160 * 91 \equiv 80\pmod{181}\)
\(R=R\cup[80,10]\)
計算\(2^{-21}\pmod{181}\),\(a=a*h= 80 * 91 \equiv 40\pmod{181}\)
\(R=R\cup[40,11]\)
計算\(2^{-22}\pmod{181}\),\(a=a*h= 40 * 91 \equiv 20\pmod{181}\)
\(R=R\cup[20,12]\)
計算\(2^{-23}\pmod{181}\),\(a=a*h= 20 * 91 \equiv 10\pmod{181}\)
\(R=R\cup[10,13]\)
計算\(2^{-24}\pmod{181}\),\(a=a*h= 10 * 91 \equiv 5\pmod{181}\)
\(R=R\cup[5,14]\)
計算\(2^{-25}\pmod{181}\),\(a=a*h= 5 * 91 \equiv 93\pmod{181}\)
\(R=R\cup[93,15]\)
計算\(2^{-26}\pmod{181}\),\(a=a*h= 93 * 91 \equiv 137\pmod{181}\)
\(R=R\cup[137,16]\)
BabyStep=\([[54,1],[27,2],[104,3],[52,4],[26,5],[13,6],[97,7],[139,8],\)
\([160,9],[80,10],[40,11],[20,12],[10,13],[5,14],[93,15],[137,16]]\)
3.計算GiantStep-------
計算\(2^{64} \equiv 44\pmod{181}\)不在R裡面
更新次方\(y=y+u= 64 + 16 = 80\)
\(b=b*c= 44 * 65536 \equiv 73\pmod{181}\)
計算\(2^{80} \equiv 73\pmod{181}\)不在R裡面
更新次方\(y=y+u= 80 + 16 = 96 \)
\(b=b*c= 73 * 65536 \equiv 117\pmod{181}\)
計算\(2^{96} \equiv 117\pmod{181}\)不在R裡面
更新次方\(y=y+u= 96 + 16 = 112 \)
\(b=b*c= 117 * 65536 \equiv 9\pmod{181}\)
計算\(2^{112} \equiv 9\pmod{181}\)不在R裡面
更新次方\(y=y+u= 112 + 16 = 128 \)
\(b=b*c= 9 * 65536 \equiv 126\pmod{181}\)
計算\(2^{128} \equiv 126\pmod{181}\)不在R裡面
更新次方\(y=y+u= 128 + 16 = 144 \)
\(b=b*c= 126 * 65536 \equiv 135\pmod{181}\)
計算\(2^{144} \equiv 135\pmod{181}\)不在R裡面
更新次方\(y=y+u= 144 + 16 = 160 \)
\(b=b*c= 135 * 65536 \equiv 80\pmod{181}\)
計算\(2^{160} \equiv 80\pmod{181}\)在\(R[10]=[80,10]\)裡面
解答\(x=y+r+C= 160 + 10 + 10 = 180 \)
\(s=u+1= 17\)
\(u=2*u= 32\)
倍增步長\(c=c^2 = 4294967296\)
(x) 180



--------------------------------
論文中演算法3.1將計算order和解離散對數問題結合在一起
\(g^x \equiv d \pmod{p}\)
\(g^{y+r}\equiv d \pmod{p}\)
\(d^{-1}g^y\equiv g^{-r}\pmod{p}\)
計算\(g^{-r}\)稱為Baby step
計算\(d^{-1}g^y\)稱為Giant step

輸入:\(d,g \in G(d\ne 1)\),初始步長\(v\)(\(v\)要是偶數)
輸出:執行結果\(t=1\),若\(d \in \langle\;g \rangle\;\),則離散對數問題的解\(x=log_g d\)
   執行結果\(t=0\),若\(d \notin \langle\;g \rangle\;\),則\(g\)的oder為\(x=|\;\langle\;g \rangle\; |\;\)
(1) \(t=2;x=0\)
(2) \(s=1;y=v;u=v\)
(3) \(h=g^{−1}\)
(4) \(a=1;b=g^v;c=b\)   /*\(a=g^{−r},b=g^y,c=g^u\)*/
(5) \(R=\phi\)
(6) \(f=d^{−1}\)
(7) while(\(t==2\))do
(8)  for(\(r=s,s+1\ldots,u\)) do  /*new baby steps*/
(9)   \(a=a*h\)
(10)   \(if(s==1)then\)     /*check if \(1\le x\le v\)*/
(11)    if(\(a==f\))then
(12)     \(x=r;t=1\)
(13)     break while
(14)    else
(15)     if(\(a==1\))then
(16)      \(x=r;t=0\)
(17)      break while
(18)     else
(19)      \(R=R\cup \{\;(a,r) \}\;\)
(20)     fi
(21)    fi
(22)   else
(23)     \(R=R\cup \{\;(a,r) \}\;\)
(24)   fi
(25)  od
(26)  while(\(t==2\) and \(y<u^2\)) do  /*giant steps*/
(27)   if(there is a number \(r\) such /*checking for discrete log.*/
(28)    that \((f*b,r)\in R)\) then
(29)    \(x=y+r;t=1\)
(30)   else
(31)    if (there is a number \(r\) such  /*checking for the order of \(g\)*/
(32)     that \((b,r)\in R\)) then
(33)     \(x=y+r;t=0\)
(34)    else
(35)     \(y=y+u\)
(36)     \(b=b*c\)
(37)    fi
(38)   fi
(39)  od
(40)  \(s=u+1;u=2u\)           /*double step-width*/
(41)  \(c=c^2\)               
(42) od
(43) return(\(t,x\))



利用Baby_stepDoubleGiant_step方法解離散對數問題副程式
(%i1)
DiscreteLogarithm(d,g,p,v):=block
([t,x,s,y,u,h,a,b,c,R,f,r],
print("1.變數初始化------------"),
print("t=",t:2),
print("x=",x:0),
print("s=",s:1),
print("y=v=",y:v),
print("u=v=",u:v),
print("h=","g"^"-1","=",g^"-1","≡",h:inv_mod(g,p),"(mod",p,")"),
print("a=",a:1),
print("b=g"^"v","=",b:g^v),
print("c=b=",c:b),
print("R=",R:[]),
print("f=","d"^"-1","=",d^"-1","≡",f:inv_mod(d,p),"(mod",p,")"),
while t=2 do
  (print("2.計算BabyStep------------"),
   for r:s thru u do
     (print("計算",g^concat("-",r),"(mod",p,"),a=a*h=",a,"*",h,"≡",a:mod(a*h,p),"(mod",p,")"),
      if s=1 then
        (if a=f then
           (print("x=r=",x:r),
            print("t=1",t:1),
            return(x)
           )
         else
           (if a=1 then
              (print("x=r=",x:r),
               print("t=0",t:0),
               return(x)
              )
            else
              (R:append(R,[[a,r]]),
               print("R=R∪",[a,r])
              )
           )
        )
      else
        (R:append(R,[[a,r]]),
         print("R=R∪",[a,r])
        )
     ),
   print("BabyStep=",R),
   print("3.計算GiantStep------------"),
   while t=2 and y<u^2 do
     (if (r:assoc(mod(f*b,p),R))#false then
        (print("計算",d^"-1","*",g,""^y,"(mod",p,"),f*b=",f,"*",b,"≡",mod(f*b,p),"(mod",p,")在R[",r,"]=",R[r],"裡面"),
         print("解答x=y+r=",y,"+",r,"=",x:y+r),
         print("狀態t=",t:1),
         return(x)
        )
      else
        (print("計算",d^"-1","*",g,""^y,"(mod",p,"),f*b=",f,"*",b,"≡",mod(f*b,p),"(mod",p,")不在R裡面"),
         print("更新次方,y=y+u=",y,"+",u,"=",y:y+u),
         print("計算",g,""^y,"(mod",p,"),b=b*c=",b,"*",c,"≡",b:mod(b*c,p),"(mod",p,")")
        )
     ),
    print("s=u+1=",s:u+1),
    print("u=2*u=",u:2*u),
    print("倍增步長,c=c"^2,"=",c:c^2),
    k:k+1
  ),
return([t,x])
)$


\(g^x \equiv d\pmod{p}\),初始步長\(v\)要是偶數
(%i5)
d:108;
g:2;
p:181;
v:2;

(d) 108
(g) 2
(p) 181
(v) 2

利用Baby_stepDoubleGiant_step方法計算g的order或解離散對數問題
(%i6) [t,x]: DiscreteLogarithm(d,g,p,v);
1.變數初始化------------
\(t=2\)
\(x=0\)
\(s=1\)
\(y=v=2\)
\(u=v=2\)
\(h=g^{-1}=2^{-1} \equiv 91 \pmod{181}\)
\(a=1\)
\(b=g^v=4\)
\(c=b=4\)
\(R=[]\)
\(f=d^{-1}=108^{-1} \equiv 119 \pmod{181}\)
2.計算BabyStep------------
計算\(2^{-1} \pmod{181}\),\(a=a*h= 1*91 \equiv 91 \pmod{181}\)
\(R=R\cup [91,1]\)
計算\(2^{-2} \pmod{181}\),\(a=a*h= 91*91 \equiv 136 \pmod{181}\)
\(R=R\cup [136,2]\)
BabyStep\(=[[91,1],[136,2]]\)
3.計算GiantStep------------
計算\(108^{-1}*2^2 \pmod{181}\),\(f*b= 119*4 \equiv 114 \pmod{181}\)不在R裡面
更新次方,\(y=y+u=2+2=4\)
計算\(2^4 \pmod{181}\),\(b=b*c= 4*4 \equiv 16 \pmod{181}\)
\(s=u+1=3\)
\(u=2*u=4\)
倍增步長,\(c=c^2=16\)
2.計算BabyStep------------
計算\(2^{-3} \pmod{181}\),\(a=a*h= 136*91 \equiv 68 \pmod{181}\)
\(R=R\cup [68,3]\)
計算\(2^{-4} \pmod{181}\),\(a=a*h= 68*91 \equiv 34 \pmod{181}\)
\(R=R\cup[34,4]\)
BabyStep\(=[[91,1],[136,2],[68,3],[34,4]]\)
3.計算GiantStep------------
計算\(108^{-1}*2^4 \pmod{181}\),\(f*b= 119*16 \equiv 94 \pmod{181}\)不在R裡面
更新次方,\(y=y+u=4+4=8\)
計算\(2^8 \pmod{181}\),\(b=b*c=16*16 \equiv 75 \pmod{181}\)
計算\(108^{-1}*2^8 \pmod{181}\),\(f*b= 119*75 \equiv 56 \pmod{181}\)不在R裡面
更新次方,\(y=y+u=8+4=12\)
計算\(2^{12} \pmod{181}\),\(b=b*c=75*16 \equiv 114 \pmod{181}\)
計算\(108^{-1}*2^{12} \pmod{181}\),\(f*b= 119*114 \equiv 172 \pmod{181}\)不在R裡面
更新次方,\(y=y+u=12+4=16\)
計算\(2^{16} \pmod{181}\),\(b=b*c=114*16 \equiv 14 \pmod{181}\)
\(s=u+1=5\)
\(u=2*u=8\)
倍增步長,\(c=c^2=256\)
2.計算BabyStep------------
計算\(2^{-5} \pmod{181}\),\(a=a*h= 34*91 \equiv 17 \pmod{181}\)
\(R=R\cup [17,5]\)
計算\(2^{-6} \pmod{181}\),\(a=a*h= 17*91 \equiv 99 \pmod{181}\)
\(R=R\cup [99,6]\)
計算\(2^{-7} \pmod{181}\),\(a=a*h= 99*91 \equiv 140 \pmod{181}\)
\(R=R\cup [140,7]\)
計算\(2^{-8} \pmod{181}\),\(a=a*h= 140*91 \equiv 70 \pmod{181}\)
\(R=R\cup [70,8]\)
BabyStep\(=[[91,1],[136,2],[68,3],[34,4],[17,5],[99,6],[140,7],[70,8]]\)
3.計算GiantStep------------
計算\(108^{-1}*2^{16} \pmod{181}\),\(f*b= 119*14 \equiv 37 \pmod{181}\)不在R裡面
更新次方,\(y=y+u=16+8=24\)
計算\(2^{24} \pmod{181}\),\(b=b*c= 14*256 \equiv 145 \pmod{181}\)
計算\(108^{-1}*2^{24} \pmod{181}\),\(f*b= 119*145 \equiv 60 \pmod{181}\)不在R裡面
更新次方,\(y=y+u=24+8=32\)
計算\(2^{32} \pmod{181}\),\(b=b*c= 145*256 \equiv 15 \pmod{181}\)
計算\(108^{-1}*2^{32} \pmod{181}\),\(f*b= 119*15 \equiv 156 \pmod{181}\)不在R裡面
更新次方,y=y+u= 32 + 8=40
計算\(2^{40} \pmod{181}\),\(b=b*c= 15*256 \equiv 39 \pmod{181}\)
計算\(108^{-1}*2^{40} \pmod{181}\),\(f*b= 119*39 \equiv 116 \pmod{181}\)不在R裡面
更新次方,y=y+u= 40 + 8=48
計算\(2^{48} \pmod{181}\),\(b=b*c= 39*256 \equiv 29 \pmod{181}\)
計算\(108^{-1}*2^{48} \pmod{181}\),\(f*b= 119*29 \equiv 12 \pmod{181}\)不在R裡面
更新次方,y=y+u= 48 + 8=56
計算\(2^{56} \pmod{181}\),\(b=b*c= 29*256 \equiv 3 \pmod{181}\)
計算\(108^{-1}*2^{56} \pmod{181}\),\(f*b= 119*3 \equiv 176 \pmod{181}\)不在R裡面
更新次方,y=y+u= 56 + 8=64
計算\(2^{64} \pmod{181}\),\(b=b*c= 3*256 \equiv 44 \pmod{181}\)
\(s=u+1=9\)
\(u=2*u=16\)
倍增步長,\(c=c^2=65536\)
2.計算BabyStep------------
計算\(2^{-9} \pmod{181},a=a*h= 70*91 \equiv 35 \pmod{181}\)
\(R=R\cup [35,9]\)
計算\(2^{-10} \pmod{181},a=a*h= 35*91 \equiv 108 \pmod{181}\)
\(R=R\cup [108,10]\)
計算\(2^{-11} \pmod{181},a=a*h= 108*91 \equiv 54 \pmod{181}\)
\(R=R\cup [54,11]\)
計算\(2^{-12} \pmod{181},a=a*h= 54*91 \equiv 27 \pmod{181}\)
\(R=R\cup [27,12]\)
計算\(2^{-13} \pmod{181},a=a*h= 27*91 \equiv 104 \pmod{181}\)
\(R=R\cup [104,13]\)
計算\(2^{-14} \pmod{181},a=a*h= 104*91 \equiv 52 \pmod{181}\)
\(R=R\cup [52,14]\)
計算\(2^{-15} \pmod{181},a=a*h= 52*91 \equiv 26 \pmod{181}\)
\(R=R\cup [26,15]\)
計算\(2^{-16} \pmod{181},a=a*h= 26*91 \equiv 13 \pmod{181}\)
\(R=R\cup [13,16]\)
BabyStep\(=[[91,1],[136,2],[68,3],[34,4],[17,5],[99,6],[140,7],[70,8],\)
\([35,9],[108,10],[54,11],[27,12],[104,13],[52,14],[26,15],[13,16]]\)
3.計算GiantStep------------
計算\(108^{-1}*2^{64} \pmod{181}\),\(f*b= 119*44 \equiv 168 \pmod{181}\)不在R裡面
更新次方,y=y+u= 64 + 16=80
計算\(2^{80} \pmod{181}\),\(b=b*c= 44*65536 \equiv 73 \pmod{181}\)
計算\(108^{-1}*2^{80} \pmod{181}\),\(f*b= 119*73 \equiv 180 \pmod{181}\)不在R裡面
更新次方,y=y+u= 80 + 16=96
計算\(2^{96} \pmod{181}\),\(b=b*c= 73*65536 \equiv 117 \pmod{181}\)
計算\(108^{-1}*2^{96} \pmod{181}\),\(f*b= 119*117 \equiv 167 \pmod{181}\)不在R裡面
更新次方,y=y+u= 96 + 16=112
計算\(2^{112} \pmod{181}\),\(b=b*c= 117*65536 \equiv 9 \pmod{181}\)
計算\(108^{-1}*2^{112} \pmod{181}\),\(f*b= 119*9 \equiv 166 \pmod{181}\)不在R裡面
更新次方,y=y+u= 112 + 16=128
計算\(2^{128} \pmod{181}\),\(b=b*c= 9*65536 \equiv 126 \pmod{181}\)
計算\(108^{-1}*2^{128} \pmod{181}\),\(f*b= 119*126 \equiv 152 \pmod{181}\)不在R裡面
更新次方,y=y+u= 128 + 16=144
計算\(2^{144} \pmod{181}\),\(b=b*c= 126*65536 \equiv 135 \pmod{181}\)
計算\(108^{-1}*2^{144} \pmod{181}\),\(f*b= 119*135 \equiv 137 \pmod{181}\)不在R裡面
更新次方,y=y+u= 144 + 16=160
計算\(2^{160} \pmod{181}\),\(b=b*c= 135*65536 \equiv 80 \pmod{181}\)
計算\(108^{-1}*2^{160} \pmod{181}\),\(f*b= 119*80 \equiv 108 \pmod{181}\)在\(R[10]=[108,10]\) 裡面
解答\(x=y+r=160+10=170\)
狀態\(t=1\)
\(s=u+1=17\)
\(u=2*u=32\)
倍增步長,\(c=c^2=4294967296\)
(%o6) \([1,170]\)




歡迎光臨 Math Pro 數學補給站 (https://math.pro/db/) 論壇程式使用 Discuz! 6.1.0