From: Christoph Fuerst Date: Thu, 6 Apr 2017 19:23:45 +0000 (+0200) Subject: Working version of Discrete Logarithm X-Git-Url: http://git.risc.jku.at/gitweb/?a=commitdiff_plain;h=c9cf51a7e878290f8320e777f7a6fc5ff892457a;p=cfuerst%2Fformal-numbers.git Working version of Discrete Logarithm --- diff --git a/discrete_log.txt b/discrete_log.txt index 8241d31..047ffb9 100644 --- a/discrete_log.txt +++ b/discrete_log.txt @@ -1,9 +1,11 @@ val M: ℕ; val K: ℕ; +val L: ℕ; type nat = ℕ[M]; type prime = ℕ[K]; +type res = ℕ[L]; pred divides(m:prime,n:prime) ⇔ ∃p:prime. m⋅p = n; @@ -30,19 +32,19 @@ proc InvModP(a:ℕ[K^2],p:prime): prime return ainv; } -proc discrete_log(p:prime,g:nat,a:nat,m:nat): nat +proc discrete_log(p:prime,g:nat,a:nat,m:nat): res requires p>1 ∧ isPrime(p) ∧ // p is a prime greater than 1 ∀b:nat. (0 < b ∧ b < p-1) ⇒ (g^b % p ≠ 1) ∧ g^(p-1)%p = 1 ∧ // g has order p-1 0 ≤ a ∧ a < p; // a is in ℤ/pℤ ensures (g^result)%p = a; { - var ret:Nat[K^2] := 0; - var A:Array[20,nat]; - var b:Array[20,nat]; + var ret:res := 0; + var A:Array[20,nat]; // Q: Is it possible to dynamically allocate?? + var b:Array[20,nat]; // Q: Is it possible to dynamically allocate?? var gim:prime := g; - A = Array[20,nat](0); - b = Array[20,nat](0); + A = Array[20,nat](0); // Q: Is it possible to dynamically allocate?? + b = Array[20,nat](0); // Q: Is it possible to dynamically allocate?? A[0] := 1; b[0] := a; @@ -53,9 +55,7 @@ proc discrete_log(p:prime,g:nat,a:nat,m:nat): nat { A[i] = A[i-1]*g%p; gim = gim*gi % p; - print A[i]; } - print gim; for var i:nat=0;i