Personal tools
You are here: Home Members folder スタッフ 関数の実装(p, qを求める)
XScale ブログ
« May 2012 »
Su Mo Tu We Th Fr Sa
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
About this blog
スタッフブログ
Recent comments
Re:Blum-Blum-Shubとは jack 2011-05-04
Re:Blum-Blum-Shubとは Anonymous User 2011-05-03
こんにちわ 村上 優奈 2010-10-18
Re:Sandgate MID ソリューションセット ¥498,000.- !!! jack 2009-08-28
大変恐縮ですが 匿名希望 2009-08-27
 
Document Actions

関数の実装(p, qを求める)

Blum-Blum-Shubを使うには、

  • 適切な X0(あたりまえだけど 0 はだめ)
  • 適度に大きい素数 p と q
  • p - 1 と q - 1 の最大公倍数が 2

というのが重要じゃないかと、書きました。こんなもの手で求められないので、それを求める関数を書きます。

def makebbspq(max, debug=0):
    from random import seed, randint # randomモジュールを使います
    seed() # 現在時刻で初期化します
    g = 0 # GCD(whileループチェッカ)
    while g != 2: # gcd が 2にならなければおわるな
        p = randint(max/7, max) # max/7 から max までの整数が帰ってきます
        q = randint(max/7, max)
        pret = primes(p, p-500) # p-500 から p までの素数を求めます。31bit範囲なら500あれば大丈夫
        qret = primes(q, q-500)
        p = pret[-1] # 最後の素数を p, q とします
        q = qret[-1]
        g = gcd(p-1, q-1) # GCDを求めます
        if debug: print p, q, g, ('NG','OK')[g==2]
    x0 = randint(max/7, max) # x0を求めます。max が 0でない限り、non-zeroです。
    return p, q, x0

これで、そこそこな値(と思われる) p, q, x0 を準備できます。

Category(s)
j@ウェブ屋
The URL to Trackback this entry is:
http://www.xscale-freak.com/Members/folder/staff/95a26570306e5b9f88c5-p-q30926c423081308b/tbping
Add comment

You can add a comment by filling out the form below. Plain text formatting.

(Required)

Powered by Plone CMS, the Open Source Content Management System