Skip to content

Commit 5068871

Browse files
authored
Release 0.4.1
* Fiat-Shamir keypair generation * Python 3 explicitly defined as runtime environment * Fiat-Shamir verification * README.md updated * Fiat-Shamir attack scheme * Fermat's factorization * Imports from cryptographic_functions fixed * Typo fixed * Elliptic curve point verification * Elliptic curve point addition * Elliptic curve point addition bug fix * Pollard's rho algorithm * Pollard's rho corner case added * README.md updated * README.md updated * ElGamal signature signing * README.md typo fixed * ElGamal signature verifying * ElGamal homomorphic multiplicative scheme * ElGamal homomorphic multiplicative decryption
1 parent c7c54ce commit 5068871

15 files changed

+851
-75
lines changed

README.md

+40-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,50 @@ Python 3.7.9 or later including pip for installing the following requirements:
1010
pip install -r requirements.txt
1111
```
1212

13-
## Usage
13+
### Creating a virtual environment
14+
15+
`venv` allows you to manage separate package installations for different projects. It essentially allows you to create
16+
a "virtual" isolated Python installation and install packages into that virtual installation. When you switch projects,
17+
you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other
18+
environments.
19+
20+
```shell
21+
python3 -m venv venv
22+
```
23+
24+
The second argument is the location, and thus the name, to create the virtual environment. Generally, you can just
25+
create this in your project and call it venv. If you name the virtual environment differently, the .gitignore must be
26+
modified accordingly.
27+
28+
### Activating a virtual environment
29+
30+
Before you can start installing or using packages in your virtual environment you’ll need to activate it.
31+
32+
| Command-line | Script |
33+
|-----------------|----------------------------------------------|
34+
| fish | $ source <venv>/bin/activate.fish |
35+
| csh/tcsh | $ source <venv>/bin/activate.csh |
36+
| PowerShell Core | $ <venv>/bin/Activate.ps1 |
37+
| cmd.exe | C:\\> <venv>\\Scripts\\activate.bat |
38+
| PowerShell | PS C:\\> <venv>\\Scripts\\Activate.ps1 |
39+
40+
### Using requirements file
41+
42+
A requirements file contains a list of dependencies to be installed using pip.
43+
44+
```shell
45+
python3 -m pip install -r requirements.txt
46+
```
47+
48+
### Usage
1449

1550
To use, simply uncomment the corresponding function in `main.py` and adjust the sample values if necessary.
1651

52+
```shell
53+
python3 main.py
54+
```
55+
1756
## To Do
1857

19-
- Include a brute force function for flexible cracking of all included algorithms in the lower prime range
20-
- Enhance the time complexity of the existing RSA `rsa_calculations.brute_force_by_key()` function from its current 2<sup>O(n)</sup>
2158
- Unify output of mathematical conditions
2259
- Add an English translation

cryptographic_functions/dh_calculations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
from cryptographic_functions import shared_functions
44
from tabulate import tabulate
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env python3
2+
3+
from cryptographic_functions import modulo_inverse_multiplicative
4+
from cryptographic_functions import shared_functions
5+
from tabulate import tabulate
6+
7+
__author__ = "Lukas Zorn"
8+
__copyright__ = "Copyright 2021 Lukas Zorn"
9+
__license__ = "GNU GPLv3"
10+
11+
12+
# Extended elliptic curve point verification
13+
def on_curve(curve, p, print_header=None):
14+
if not print_header:
15+
print(tabulate([['Verifikation eines Punktes auf der elliptischen Kurve']], tablefmt='fancy_grid'))
16+
else:
17+
print(tabulate([[f'<AUXILIARY {print_header}>Verifikation eines Punktes auf der elliptischen Kurve']],
18+
tablefmt='fancy_grid'))
19+
20+
# Unpack all curve parameters and the point into its components
21+
a, b, n = curve
22+
x_p, y_p = p
23+
24+
v_p = (y_p ** 2) % n == ((x_p ** 3) + (a * x_p) + b) % n
25+
26+
# Calculation path output
27+
print(
28+
f'Durch das Einsetzen des Punktes P = (x_p|y_p) = ({x_p}|{y_p}) in die elliptischen Kurve y^2 = x^3 + a * x + '
29+
f'b im GF({n}) wird berechnet:\n'
30+
f'{y_p}^2 = {x_p}^3 + {a} * {x_p} + {b} mod {n}\n'
31+
f'{y_p ** 2} = {x_p ** 3} + {a * x_p} + {b} mod {n}\n'
32+
f'{y_p ** 2} = {(x_p ** 3) + (a * x_p) + b} mod {n}\n'
33+
f'{(y_p ** 2) % n} = {((x_p ** 3) + (a * x_p) + b) % n}', end='\n\n')
34+
if v_p:
35+
print(f'Folglich liegt der Punkt P auf der elliptischen Kurve, da {(y_p ** 2) % n} = '
36+
f'{((x_p ** 3) + (a * x_p) + b) % n}.')
37+
else:
38+
print(f'Folglich liegt der Punkt P nicht auf der elliptischen Kurve, da {(y_p ** 2) % n} != '
39+
f'{((x_p ** 3) + (a * x_p) + b) % n}.')
40+
shared_functions.print_auxiliary(print_header)
41+
return v_p
42+
43+
44+
# Elliptic curve point addition
45+
def addition(curve, p, q, print_matrix=False, print_linear_factorization=True):
46+
print(tabulate([['Addition von Punkten auf der elliptischen Kurve']], tablefmt='fancy_grid'))
47+
48+
# Unpack all curve parameters and both points into its components
49+
a, b, n = curve
50+
x_p, y_p = p
51+
x_q, y_q = q
52+
53+
# Choose a point p that lies on the elliptic curve
54+
if not on_curve(curve, p, 1):
55+
print(f'Der Punkt P = ({x_p}|{y_p}) muss auf der elliptischen Kurve liegen.')
56+
return -1
57+
58+
# Choose a point q that lies on the elliptic curve
59+
if not on_curve(curve, q, 2):
60+
print(f'Der Punkt Q = ({x_q}|{y_q}) muss auf der elliptischen Kurve liegen.')
61+
return -1
62+
63+
# Calculation of m
64+
m_n = (y_p - y_q) % n
65+
m_d = modulo_inverse_multiplicative.mim(n, (x_p - x_q) % n, print_matrix, print_linear_factorization, 3)
66+
m = (m_n * m_d) % n
67+
68+
# Calculation of x_r, y_r and y_r_i
69+
x_r = ((m ** 2) - x_p - x_q) % n
70+
y_r = (y_p - m * (x_p - x_r)) % n
71+
y_r_i = -y_r % n
72+
73+
# Choose a point r that lies on the elliptic curve
74+
if not on_curve(curve, (x_r, y_r_i), 4):
75+
print(f'Der Punkt R = ({x_r}|{y_r_i}) muss auf der elliptischen Kurve liegen.')
76+
return -1
77+
78+
# Calculation path output
79+
print(
80+
f'Im endlichen Zahlenkörper GF({n}) sollen auf Basis der Kurve y^2 = x^3 + {a} * x + {b} die Punkte '
81+
f'P = ({x_p}|{y_p}) und Q = ({x_q}|{y_q}) additiv verknüpft werden, um den Punkt R zu bestimmen.',
82+
end='\n\n')
83+
print(
84+
f'(1) Verifiziere, dass P = ({x_p}|{y_p}) auf der elliptischen Kurve liegt:\n'
85+
f'<AUXILIARY 1>Achtung: Die Namen der Variablen können abweichen!</AUXILIARY 1>\n'
86+
f'(2) Verifiziere, dass Q = ({x_q}|{y_q}) auf der elliptischen Kurve liegt:\n'
87+
f'<AUXILIARY 2>Achtung: Die Namen der Variablen können abweichen!</AUXILIARY 2>', end='\n\n')
88+
print(
89+
f'Für die additive Verknüpfung der beiden Punkte wird nun die Steigung m in GF({n}) berechnet:\n'
90+
f'm = (y_p - y_q) / (x_p - x_q) % n\n'
91+
f'm = (y_p - y_q) * (x_p - x_q)^-1 % n\n'
92+
f'm = ({y_p} - {y_q}) * ({x_p} - {x_q})^-1 % {n}\n'
93+
f'm = {m_n} * {x_p - x_q}^-1 % {n}\n'
94+
f'<AUXILIARY 3>Achtung: Die Namen der Variablen können abweichen!</AUXILIARY 3>\n'
95+
f'm = {m_n} * {m_d} % {n}\n'
96+
f'm = {m}', end='\n\n')
97+
print(
98+
f'Daraus folgt für die Berechnung von -R = (x_r|y_r):\n'
99+
f'x_r = ((m ** 2) - x_p - x_q) % n\n'
100+
f'x_r = (({m} ** 2) - {x_p} - {x_q}) % {n}\n'
101+
f'x_r = {(m ** 2) - x_p - x_q} % {n}\n'
102+
f'x_r = {x_r}\n'
103+
f'y_r = (y_p - m * (x_p - x_r)) % n\n'
104+
f'y_r = ({y_p} - {m} * ({x_p} - {x_r})) % {n}\n'
105+
f'y_r = {y_p - m * (x_p - x_r)} % {n}\n'
106+
f'y_r = {y_r}', end='\n\n')
107+
print(
108+
f'Aus dem Punkt -R = ({x_r}|{y_r}) kann nun mittels Punktnegation für y_r der Punkt R = ({x_r}|{y_r_i}) '
109+
f'berechnet werden:\n'
110+
f'y_r_i = -(y_r) % n\n'
111+
f'y_r_i = {-y_r} % {n}\n'
112+
f'y_r_i = {y_r_i}', end='\n\n')
113+
print(
114+
f'(3) Verifiziere, dass R = ({x_r}|{y_r_i}) auf der elliptischen Kurve liegt:\n'
115+
f'<AUXILIARY 4>Achtung: Die Namen der Variablen können abweichen!</AUXILIARY 4>', end='\n\n')
116+
return x_r, y_r_i

0 commit comments

Comments
 (0)