4. Anhang 4.1 Wertetabellen zum 2. Algorithmus //Suche alle k, welche quadratische Reste mod 64 sind print "Quadratische Reste mod 64:"; for k:=0 to 31 do print (k^2 mod 64); end for; k 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 q64[k] 1 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 g11[k] 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 q11[k] 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 //Suche alle k, welche quadratische Reste mod 63 sind print "Quadratische Reste mod 63:"; for k:=0 to 31 do print (k^2 mod 63); end for; k 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 q63[k] 1 1 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 q63[k] 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 q63[k] 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 //Suche alle k, welche quadratische Reste mod 65 sind print "Quadratische Reste mod 65:"; for k:=0 to 32 do print (k^2 mod 65); end for; k 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 q65[k] 1 1 0 0 1 0 0 0 0 1 1 0 0 0 1 0 1 0 0 0 0 0 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 q65[k] 0 0 0 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 0 0 0 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 q65[k] 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 0 0 1 0 0 1 //Suche alle k, welche quadratische Reste mod 11 sind print "Quadratische Reste mod 11:"; for k:=0 to 5 do print (k^2 mod 11); end for; k 0 1 2 3 4 5 6 7 8 9 10 q11[k] 1 1 0 1 1 1 0 0 0 1 0
4.2 MAGMA-Codes mit Beispielen 1. Algorithmus: // Integer Square Root n:=144; x:=n; y:=floor((x + Floor(n div x)) div 2); while (y lt x) do print y; x:=y; y:=floor((x + Floor(n div x)) div 2); end while; Ausgabefenster in MAGMA 72 37 20 13 12 Die ganzzahlige Quadratwurzel von 144 ist: 12 print "Die ganzzahlige Quadratwurzel von",n,"ist:",x; 2. Algorithmus: // Square Test n:=4096; q11:=[0,1,3,4,5,9]; q63:=[0,1,4,7,9,16,18,22,25,28,36,37,43,46,49,58]; q64:=[0,1,4,9,16,17,25,33,36,41,49,57]; q65:=[0,1,4,9,10,14,16,25,26,29,30,35,36,39,40,49,51,55,56,61,64]; r:=(n mod 45045); t:=(n mod 64); a:=(r mod 63); b:=(r mod 65); c:=(r mod 11); x:=n; y:=floor((x + Floor(n div x)) div 2); //Probe 64 if t in q64 then print "q64[", t,"], also berechne: (",n,"mod 45045 ) =", r; //Probe 63 if a in q63 then print "q63[", a, "] = 1, also koennte", n, "eine Quadratzahl sein."; //Probe 65 if b in q65 then print "q65[", b, "] = 1, also koennte", n, "eine Quadratzahl sein."; //Probe 11 if c in q11 then print "q11[", c, "] = 1, also koennte", n, "eine Quadratzahl sein."; //Berechnung der Quadratwurzel while (y lt x) do x:=y; y:=floor((x+floor(n div x)) div 2); end while; print "Berechnung der ganzzahligen Quadratwurzel:", x; //Test, ob dies wirklich die Quadratwurzel if (x^2 eq n) then print "Ergebnis:", n, "ist eine Quadratzahl mit Quadratwurzel", x; else print "Ergebnis:", n, "ist keine Quadratwurzel."; else print "q11[", c, "] = 0, also ist", n, "keine Quadratzahl."; else print "q65[", b, "] = 0, also ist", n, "keine Quadratzahl."; else print "q63[", a, "] = 0, also ist", n, "keine Quadratzahl."; else print "q64[", t, "] = 0, also ist", n, "keine Quadratzahl.";
Ausgabefenster in MAGMA: q64[ 0 ], also berechne: ( 4096 mod 45045 ) = 4096 q63[ 1 ] = 1, also koennte 4096 eine Quadratzahl sein. q65[ 1 ] = 1, also koennte 4096 eine Quadratzahl sein. q11[ 4 ] = 1, also koennte 4096 eine Quadratzahl sein. Berechnung der ganzzahligen Quadratwurzel: 64 Ergebnis: 4096 ist eine Quadratzahl mit Quadratwurzel 64 3. Algorithmus: //Prime Power Test n:=2197; p:=2; q:=n; R:=ResidueClassRing(q); f:=factorization(q-1); t:=f[1][2]; m:=(q-1) div (2^t); //1. Schritt: Fall n gerade if IsEven(n) then print "1. Schritt:", n, "ist gerade -> Finaler Test (Schritt 4)"; //4. Schritt: Finaler Test if IsPrime(p) then //Mehrmaliges Dividieren k:=0; repeat k:=k+1; until (p^k ge n); if (p^k eq n) then print "4. Schritt:", n, "ist Primzahlpotenz von p =", p, "mit Grad k =", k; else print "4. Schritt:", n, "ist keine Primzahlpotenz"; else print "Setze q:=", p, " -> Miller-Rabin-Test (Schritt 2)"; else print "1. Schritt:", n, "ist ungerade -> Miller-Rabin-Test (Schritt 2)"; //2. Schritt: Miller-Rabin-Test print "2. Schritt: Anwendung des Miller-Rabin-Tests:"; //Teste höchstens 10 mal for b:=1 to 10 do a:=random(r); //Teste, ob a Einheit if (not (GCD(a,q) eq 1)) then print a, "nicht teilerfremd zu", q, ",also",q, "sicher nicht prim"; else //Teste, ob MR1 erfüllt ist x:=a^m; if (x eq 1) then print a, "^m=1, also", q, "hoechstens mit Wkeit", (1/4)^b, "nicht prim"; //Falls MR1 nicht erfüllt, teste, ob MR2 erfüllt else treffer:=false; s:=0; while ((not treffer) and (s lt t)) do if (x eq -1) then treffer:=true; print a,"^(m*2^", s, ")=-1, also hoechstens mit Wkeit", (1/4)^b, "nicht prim"; break; else s:=s+1; x:=x^2; end while; if (s eq t) then print a, "erfuellt die MR-Bedingung nicht, also ist", a, "Zeuge, dass", q, "nicht prim ist
-> Schritt 3"; //3. Schritt: Berechnung des ggt q:=n; d:=gcd(a^q-a,q); if (d eq 1) or (d eq q) then print n, "ist keine Primzahlpotenz"; else print "3. Schritt: ggt(",a,"^",q,"-",a,",",q,") =", d, " -> erneute Anwendung des Miller-Rabin-Tests (Schritt 2)"; break; end for; // 2. Schritt: Erneute Anwendung des Miller-Rabin-Tests n:=2197; q:=13; R:=ResidueClassRing(q); f:=factorization(q-1); t:=f[1][2]; m:=(q-1) div (2^t); print "2. Schritt: Erneute Anwendung des Miller-Rabin-Tests:"; //Teste höchstens 10 mal for b:=1 to 10 do a:=random(r); //Teste, ob a Einheit if (not (GCD(a,q) eq 1)) then print a,"nicht teilerfremd zu",q,",also",q,"sicher nicht prim"; else //Teste, ob MR1 erfüllt ist x:=a^m; if (x eq 1) then print a, "^m=1, also",q,"hoechstens mit Wkeit", (1/4)^b, "nicht prim"; Hier wird das zu untersuchende n eingetragen und das im Schritt 3 berechnete q übernommen. //Falls MR1 nicht erfüllt, teste, ob MR2 erfüllt else treffer:=false; s:=0; while ((not treffer) and (s lt t)) do if (x eq -1) then treffer:=true; print a,"^(m*2^", s, ")=-1, also",q,"hoechstens mit Wkeit", (1/4)^b, "nicht prim"; break; else s:=s+1; x:=x^2; end while; if (s eq t) then print a,"erfuellt die MR-Bedingung nicht, also ist",a,"zeuge, dass",q,"nicht prim ist -> Schritt 3"; //3. Schritt: Berechnung des ggt d:=gcd(a^q-a,q); if (d eq 1) or (d eq q) then print n, "ist keine Primzahlpotenz"; else print "3. Schritt: ggt(",a,"^",q,"-",a,",",q,") =", d, " -> Setze q:=",d,"und erneute Anwendung des Miller-Rabin-Tests (Schritt 2)"; break; end for;
//4. Schritt: Finaler Test n:=2197; q:=13; if IsPrime(q) then Hier wird das zu untersuchende n eingetragen und das im Schritt 3 berechnete q übernommen. //Mehrmaliges Dividieren k:=0; repeat k:=k+1; until (q^k ge n); if (q^k eq n) then print "4. Schritt:", n, "ist Primzahlpotenz von p =", q, "mit Grad k =", k; else print "4. Schritt:", n, "ist keine Primzahlpotenz, da",n,"=",q,"^k fuer kein k erfuellt ist"; else print "Setze q:=", q, " -> Miller-Rabin-Test (Schritt 2)"; Ausgabefenster MAGMA: n gerade 1. Schritt: 2048 ist gerade -> Finaler Test (Schritt 4) 4. Schritt: 2048 ist Primzahlpotenz von p = 2 mit Grad k = 11 Ausgabefenster MAGMA: n ungerade 1. Schritt: 2197 ist ungerade -> Miller-Rabin-Test (Schritt 2) 2. Schritt: Anwendung des Miller-Rabin-Tests: 1633 erfuellt die MR-Bedingung nicht, also ist 1633 Zeuge, dass 2197 nicht prim ist -> Schritt 3 3. Schritt: ggt( 1633 ^ 2197-1633, 2197 ) = 13 -> erneute Anwendung des Miller-Rabin-Tests (Schritt 2) 2. Schritt: Erneute Anwendung des Miller-Rabin-Tests: 10 ^(m*2^ 0 )=-1, also 13 hoechstens mit Wkeit 1/4 nicht prim 6 ^(m*2^ 1 )=-1, also 13 hoechstens mit Wkeit 1/16 nicht prim 4 ^(m*2^ 0 )=-1, also 13 hoechstens mit Wkeit 1/64 nicht prim 5 ^(m*2^ 1 )=-1, also 13 hoechstens mit Wkeit 1/256 nicht prim 4 ^(m*2^ 0 )=-1, also 13 hoechstens mit Wkeit 1/1024 nicht prim 5 ^(m*2^ 1 )=-1, also 13 hoechstens mit Wkeit 1/4096 nicht prim 11 ^(m*2^ 1 )=-1, also 13 hoechstens mit Wkeit 1/16384 nicht prim 4 ^(m*2^ 0 )=-1, also 13 hoechstens mit Wkeit 1/65536 nicht prim 2 ^(m*2^ 1 )=-1, also 13 hoechstens mit Wkeit 1/262144 nicht prim 5 ^(m*2^ 1 )=-1, also 13 hoechstens mit Wkeit 1/1048576 nicht prim 4. Schritt: 2197 ist Primzahlpotenz von p = 13 mit Grad k = 3