|
@@ -33,6 +33,15 @@ def Dsequence():
|
33
|
33
|
val = val + 2
|
34
|
34
|
|
35
|
35
|
def Legendre(a, p):
|
|
36
|
+ """Function for calculating Legendre symbol.
|
|
37
|
+
|
|
38
|
+ Note that this is only supposed to be defined if p is an odd prime, but we
|
|
39
|
+ don't know in advance if that is true - will therefore only throw and error
|
|
40
|
+ if p is even.
|
|
41
|
+
|
|
42
|
+ Uses original power definition from
|
|
43
|
+ <https://en.wikipedia.org/wiki/Legendre_symbol>
|
|
44
|
+ """
|
36
|
45
|
if (p % 2 == 0):
|
37
|
46
|
raise ValueError("p must be odd, is {}".format(p))
|
38
|
47
|
lv = pow(a, (p-1)//2, p)
|
|
@@ -41,8 +50,17 @@ def Legendre(a, p):
|
41
|
50
|
return lv
|
42
|
51
|
|
43
|
52
|
def Jacobi(a, n):
|
|
53
|
+ """Function for calculating Jacobi symbol.
|
|
54
|
+
|
|
55
|
+ Note that this is only defined for positive odd integers n.
|
|
56
|
+
|
|
57
|
+ Uses algorithm from
|
|
58
|
+ <https://en.wikipedia.org/wiki/Jacobi_symbol#Calculating_the_Jacobi_symbol>
|
|
59
|
+ """
|
|
60
|
+ if n < 1:
|
|
61
|
+ raise ValueError("n must be positive")
|
44
|
62
|
if (n % 2 == 0):
|
45
|
|
- raise ValueError("n must be odd, is {}".format(n))
|
|
63
|
+ raise ValueError("n must be odd")
|
46
|
64
|
if a % n != a:
|
47
|
65
|
return Jacobi(a%n, n)
|
48
|
66
|
if a != 0 and a % 2 == 0:
|
|
@@ -77,5 +95,3 @@ for n in range(1, 21, 2):
|
77
|
95
|
|
78
|
96
|
|
79
|
97
|
|
80
|
|
-
|
81
|
|
-
|