-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomainparms.sh
More file actions
executable file
·70 lines (61 loc) · 1.66 KB
/
domainparms.sh
File metadata and controls
executable file
·70 lines (61 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Tool to experiment with domain parameters that can be
# used for the "manual" diffie hellman calculations ( g^a % p ) that's
# done in the workshop.
#
# If you use just any random number, you often get strange
# results, p.e. the result being either equal to one of the
# domain parameters g, p or a. Or the result being very small (p.e. 1).
#
# To reduce the risk of dissatisfied customers of the workshop,
# try to use random 4-digit primes for p and
# any 5-digit random number for g and a.
#
# Apparently, if you use 5-digit random numbers for all the parameters,
# you should be fine as well.
#
# Run the skript to make 1000 testruns with current random params and have the
# "strange" results printed to stdout
#
# Adjust the function randPrime to check how large the prime should be
# Adjust the function rand to check how large the random numbers should be
function rand() {
echo `shuf -i10000-100000 -n1`
}
function randPrime() {
factor {100..1000} | awk 'NF==2{print $2}' | sort -R | head -n 1
}
function strange() {
g=$1;
p=$2;
a=$3;
r=$4;
if [ $g -eq $r ] ||
[ $p -eq $r ] ||
[ $a -eq $r ] ||
[ $r -lt 10 ] ||
[ $r -eq 1 ] ; then
return -1;
fi
return 0;
}
PROBS=""
CNT=1
for i in `seq 1000`; do
p=$(rand)
g=$(rand)
a=$(rand)
r=`echo "$g^$a%$p"|bc`
CNT=`echo "($CNT + 1) % 10" | bc`
if [ $CNT -eq 0 ]; then
echo -n "|"
else
echo -n "."
fi
#echo "$g^$a%$p = $r"
strange $g $p $a $r
if [ $? -ne 0 ]; then
PROBS="$PROBS\necho \"$g^$a%$p\" | bc = $r"
fi
done
echo -e "\nStrange results:$PROBS"