aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-10-10 22:52:38 +0200
committertomsmeding <tom.smeding@gmail.com>2016-10-10 22:52:38 +0200
commit5c19ba3ba7d07d1619e607b65b698e4eb65f6e0c (patch)
treeb32e9a43cf48dee52d23f0c9219bfa29299fded6
parentc33f462475a30ad560d0153a006796f47563d760 (diff)
Improve comments
-rwxr-xr-xenvelope/gcdtest.sh21
-rw-r--r--primes.cpp2
-rw-r--r--primes.h4
3 files changed, 24 insertions, 3 deletions
diff --git a/envelope/gcdtest.sh b/envelope/gcdtest.sh
new file mode 100755
index 0000000..be6ff7e
--- /dev/null
+++ b/envelope/gcdtest.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+function go() {
+ keylen="$1"
+ total="$2"
+ for i in $(seq 1 "$total"); do
+ ./envelope -k "$keylen" 2>&1 | head -1 | cut -d' ' -f3 | outerr
+ done | sort -n | uniq -c | head -1 | awk '{print $1}'
+}
+
+function percentage() {
+ printf "%d bits, %d trials: %s%% 2's\n" "$1" "$2" "$(bc <<<"100*$(go $1 $2)/$2")"
+}
+
+percentage "$1" "$2"
+
+#percentage 512 20
+#percentage 700 20
+#percentage 900 20
+#percentage 1024 10
+#percentage 1400 10
+#percentage 2048 10
diff --git a/primes.cpp b/primes.cpp
index 0bda8f6..07933d5 100644
--- a/primes.cpp
+++ b/primes.cpp
@@ -34,7 +34,7 @@ pair<Bigint,Bigint> genprimepair(Rng &rng,int nbits){
// (2^x + 2^(x-2))^2 = 2^(2x) + 2^(2x-1) + 2^(2x-4)
// ergo: (2^x + lambda*2^(x-2))^2 \in [2^(2x), 2^(2x+1)), for lambda \in [0,1]
// To make sure the primes "differ in length by a few digits" [RSA78], we use x1=x-2 in the first
- // prime and x2-x+2 in the second
+ // prime and x2=x+2 in the second random prime searched
int x1=nbits/2-2,x2=(nbits+1)/2+2;
assert(x1+x2==nbits);
return make_pair(
diff --git a/primes.h b/primes.h
index 0be8aa7..25d0226 100644
--- a/primes.h
+++ b/primes.h
@@ -8,10 +8,10 @@ extern std::vector<int> smallprimes;
void fillsmallprimes();
-//for use in RSA (pass target number of bits of N)
+//For use in RSA (pass target number of bits of N)
std::pair<Bigint,Bigint> genprimepair(Rng &rng,int nbits);
-//finds random in range [low,high]; throws range_error("No primes") if no prime found
+//Finds random in range [low,high]; throws range_error("No primes") if no prime found
//Will call fillsmallprimes() if not yet done
Bigint randprime(Rng &rng,const Bigint &low,const Bigint &high);