]> git.leopard-lacewing.eu Git - zahlenTA.git/commitdiff
+lib polrho pepin fermat lucl ... UElib
authorPeter Schaefer <schaeferpm@gmail.com>
Thu, 21 Jun 2012 08:30:23 +0000 (10:30 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Thu, 21 Jun 2012 08:30:23 +0000 (10:30 +0200)
muss noch getestet werden!

UE/lib.py

index 068f0f86de69638ea390e0b41ca6d9546a9d16c1..f3c8773fe956deb4e32c86f54b9ea4f17175e8b9 100644 (file)
--- a/UE/lib.py
+++ b/UE/lib.py
@@ -341,7 +341,7 @@ def jacobi_tex(z, n):
 
 
 #Square and Multiply (x,k,*,e)
-def sqmult(x,k,func,e):
+def sqmult(x,k,func=lambda x,y:x*y,e=1):
     y = e;
     while k:
         if(k%2):
@@ -352,7 +352,7 @@ def sqmult(x,k,func,e):
 
 #Square and Multiply (x,k,*,e) mit TeX Ausgabe
 def sqmult_tex(x,k,func,e):
-    y = e;
+    y = e
     print "\\begin{array}{cccc}"
     print "  x & y & k & k \\mod 2\\\\\\hline"
     print " ", x, "&" , y , "&" , k, "&" , k%2, "\\\\"
@@ -364,3 +364,29 @@ def sqmult_tex(x,k,func,e):
         print " ", x, "&" , y , "&" , k, "&" , k%2, "\\\\"
     print "\\end{array}"
     return y
+
+def fermat(n)
+       return 2**(2**n)+1
+       
+def pepin(n)
+       return sqmult(3,(2**(2**n))/2,lambda x,y:(x*y)%(2**(2**n)+1),1) == 2**(2**n)
+       
+def lucl(p)
+       s = 4
+       if !isprime(p):
+               return 0
+       for i in range(1,p-2):
+               s = s*s-2 mod 2**(p-1)
+       return s==0
+
+def polrho(n,x=3,y=3,e=2,a=1)
+       c = 0
+       while :
+               c =c+1
+               x = sqmult(x,e,lambda x,y:x*y mod n) +a
+               y = sqmult(y,e,lambda x,y:x*y mod n) +a
+               y = sqmult(y,e,lambda x,y:x*y mod n) +a
+               if gcd(x-y,n)>1:
+                       return gcd(y-y,n),c
+               
+       
\ No newline at end of file