1. 程式人生 > >Baby-step giant-step算法+拓展

Baby-step giant-step算法+拓展

20px wiki ace 資料 cati them mod 方法 style

寫在前面:

  學習筆記,方便復習,學習資料來自網絡,註明出處

我們都在努力奔跑,我們都是追夢人


技術分享圖片

結論

  In group theory, a branch of mathematics, the baby-step giant-step is a meet-in-the-middle algorithm for computing the discrete logarithm

  The algorithm is based on a space–time tradeoff. It is a fairly simple modification of trial multiplication, the naive method of finding discrete logarithms

——Wikipedia

譯:

  在群論中,作為數學的一個分支,BSGS算法是計算離散對數的一種中間交集算法

  該算法時間復雜度/空間復雜度相權衡。是對試乘法的一個相當簡單的修改,這是一種求離散對數的幼稚方法

實現

  • 裸的Baby-step giant-step算法

  首先,要知道什麽是[?]離散對數

  BSGS算法的輸入輸出:

    輸入:一個n階的模群G,群元素β

    輸出:一個整數x,滿足αxβ (G中)

  實際上是[?]拓展歐幾裏得算法的應用③

  已知正整數ab素數p,求一個整數x使滿足axb (MOD p)


技術分享圖片

  希望求得x,把x拆一下,拆成⌈p⌉*i+n

  其中:

    0<=i<⌈p⌉

    0<=n<⌈p⌉

  (A⌈p⌉)i*An ≡ B (mod p)

  這裏使用[?]拓展歐幾裏得算法的應用②

  因為p是質數,保證了解的存在,自然能求出來一個解

  從小到大枚舉i,那麽得到的x也就從小到大

  至於An,知道了An等於幾,怎麽知道n是幾呢?

  有一個很聰(diu)明(ren)的方法,事先把An與n存到hash表(或者map)裏(占一定時間),查一下就好了

  • 拓展Baby-step giant-step算法

  實際上是[?]拓展歐幾裏得算法的應用⑤

  (A⌈k⌉)i*An ≡ B (mod k)

  此處k為任意正整數

  利用[?]拓展歐幾裏得算法的應用④

  輕松判斷有解無解,有解就求出來

循環什麽的待填坑

代碼什麽的摸了

Baby-step giant-step算法+拓展