1 / 15

# 1.5.2 The Algorithm of Cornacchia - PowerPoint PPT Presentation

1.5.2 The Algorithm of Cornacchia. 今回の内容. Algorithm1.5.2(Cornacchia) Algorithm1.5.2 の実装 Algorithm1.5.2 の Example Algorithm1.5.3(Modified-Cornacchia). Algorithm1.5.2(Cornacchia). より、一般的に・・・・. Algorithm1.5.2(Cornacchia). Input: Output: Step1: Step2:. Algorithm1.5.2(Cornacchia). Step3:

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about '1.5.2 The Algorithm of Cornacchia' - gallia

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### 1.5.2The Algorithm of Cornacchia

• Algorithm1.5.2(Cornacchia)

• Algorithm1.5.2の実装

• Algorithm1.5.2のExample

• Algorithm1.5.3(Modified-Cornacchia)

より、一般的に・・・・

• Input:

• Output:

• Step1:

• Step2:

• Step3:

• Step4:

このbがxの候補になる

Euclid Algorithmの適用

• 証明について

• F. Morain, J.-L. Nicolas による証明がある.

(URL)

http://web.math.hr/~duje/tbkript/tbksem.html

• について

• Primes of the form x2+ny2 (Cox, David A. 著) に多くのことが書かれている.

Pythonでの実装

import math

import kro1

import shanks

import square_test

def cornacchia(d,p):

k = kro1.kro_b(-d,p)

if k == -1:

return "no solution"

x0= shanks.shanks(-d,p)

if x0 == 0:

return "no solution"

if x0 < p/2:

x0 = p – x0

a = p

b = x0

l = int(math.floor(math.sqrt(p)))

while b > l:

r = a % b

a = b

b = r

c = (p - (b ** 2)) / d

t = squaretest.square_test(c)

if ((d % (p - (b ** 2)) != 0) or

square_test.square_test(c) > 1):

return (b,t)

return "no solution"

Algorithm1.5.1

Algorithm1.7.3

Pythonでの実装(Algorithm1.5.1)

k = kro1.kro_b(n,g)

z = (n ** q) % g

y = z

r = e

x = (c ** ((q - 1) // 2)) % g

b = (c * (x ** 2)) % g

x = (c * x) % g

while b % g != 1:

m = 1

while ((b ** (2 ** m)) % g) != 1:

m = m + 1

if m == r:

print “[a] is not a quadratic residue mod p"

return 0

t = (y ** (2 ** (r - m - 1))) % g

y = (t ** 2) % g

r = m % g

x = (x * t) % g

b = (b * y) % g

return x

import math

import random

import kro1

def shanks(c,g):

temp = g -1

e = 0

while temp % 2 == 0:

temp = temp // 2

e = e + 1

q = (g-1) // 2**e

k = 0

while k != -1:

n =int(math.floor

(1000*random.random()))

Pythonでの実装(Algorithm1.7.1&3)

for k in range(0,64):

q64.append(0)

for k in range(0,32):

q64[(k ** 2) % 64] = 1

for k in range(0,65):

q65.append(0)

for k in range(0,33):

q65[(k ** 2) % 65] = 1

t = c % 64

if q64[t] == 0:

return "sono1"

r = c % 45045

if q63[r % 63] == 0:

return "sono2"

if q65[r % 65] == 0:

return "sono3"

if q11[r % 11] == 0:

return "sono4"

x = c

y = 0

y = math.floor

((x + math.floor(c/x))/2)

while y < x:

x = y

y = math.floor

((x + math.floor(c/x))/2)

if int(math.floor(x ** 2))

== int(math.floor(c)):

return 1

else:

return 0

import math

def square_test(c):

q11 = []

q63 = []

q64 = []

q65 = []

for k in range(0,11):

q11.append(0)

for k in range(0,6):

q11[(k ** 2) % 11] =1

for k in range(0,63):

q63.append(0)

for k in range(0,32):

q63[(k ** 2) % 63] = 1

p/2<x0<p

となるように

• Step1:

• Step2:

• Step3: a b r

97 80 -

80 17 5

17 12 5

12 5 5

• Step4:

Euclid Algorithm

を適用

になっている

(1)

(2)

(3)

• (3)の場合,Algorithm1.5.2を適用することができない

• 1.5.2を修正したAlgorithm1.5.3を用いることで,この問題を解決することができる

のとき

• Input:

• Output:

• Step1:

• Step2:

1.5.2との違い

• Step3:

• Step4:

1.5.2との違い