Skip to content

Commit

Permalink
Merge pull request #4 from lonkey/release-0.3.1
Browse files Browse the repository at this point in the history
Release 0.3.1
  • Loading branch information
lonkey committed Jan 26, 2021
2 parents 0b4075f + 8ef1ea6 commit 84293b6
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 46 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ To use, simply uncomment the corresponding function in `main.py` and adjust the
## To Do

- Include a brute force function for flexible cracking of all included algorithms in the lower prime range
- Enhance the time complexity of the existing RSA `rsa_calculations.brute_force_by_key()` function from its current 2<sup>O(n)</sup>
- Unify output of mathematical conditions
- Add an English translation
3 changes: 0 additions & 3 deletions cryptographic_functions/dh_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# Diffie–Hellman key exchange
Expand Down
3 changes: 0 additions & 3 deletions cryptographic_functions/elgamal_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# ElGamal keypair generation
Expand Down
3 changes: 0 additions & 3 deletions cryptographic_functions/modulo_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# Addition in finite sets
Expand Down
3 changes: 0 additions & 3 deletions cryptographic_functions/modulo_cyclic_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# Cyclic groups
Expand Down
3 changes: 0 additions & 3 deletions cryptographic_functions/modulo_inverse_additive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# Additive inverse element in finite sets
Expand Down
3 changes: 0 additions & 3 deletions cryptographic_functions/modulo_inverse_multiplicative.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# Multiplicative inverse element in finite sets
Expand Down
39 changes: 21 additions & 18 deletions cryptographic_functions/rsa_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# RSA keypair generation
Expand Down Expand Up @@ -138,37 +135,43 @@ def decryption(private_key, c):


# RSA Brute-force
def brute_force_by_key(any_key):
def brute_force_by_key(any_key, p_n=None):
print(tabulate([['RSA Brute-Force Angriff (schlüsselbasiert)']], tablefmt='fancy_grid'))

# Unpack the key into its components
a, n = any_key

# Choose multiple integers x such that 0 ≤ x < n
x, y, z = random.sample(range(n), 3)
# Test for half of all possible plaintexts or 5
if p_n is None:
p_n = n // 2 if n < 50 else 5

# Choose an integer p_n such that 1 ≤ p_n < n
if p_n not in range(1, n):
print(f'Für die Variable p_n = {p_n} muss gelten 1 ≤ {p_n} < {n}.')
return -1

# Choose p_n plaintexts p such that 0 ≤ p < n
p = random.sample(range(n), p_n)

# Encryption
x_c = (x ** a) % n
y_c = (y ** a) % n
z_c = (z ** a) % n
c = [(x ** a) % n for x in p]

# Brute-force
b = []
for v in range(n):
if x != (x_c ** v) % n:
continue
if y != (y_c ** v) % n:
continue
if z != (z_c ** v) % n:
continue
b.append(v)
for (p_x, c_x) in zip(p, c):
b_x = []
for n_x in range(n):
if p_x == (c_x ** n_x) % n:
b_x.append(n_x)
b.append(b_x)
b = sorted(set(b[0]).intersection(*b))

# Calculation path output
if len(b) < 1:
print(
f'Das Gegenstück für den Schlüssel K = {{{a}, {n}}} konnte nicht ermittelt werden.', end='\n\n')
return -1
print(
f'Mögliche Gegenstücke für den Schlüssel K = {{{a}, {n}}} mit den Testwerten x = {x}, y = {y} und z = {z} sind:')
f'Mögliche Gegenstücke für den Schlüssel K = {{{a}, {n}}} sind:')
print(tabulate(zip(*(b, [n] * len(b))), headers=['b', 'n'], tablefmt='pretty'), end='\n\n')
return b[0], n
3 changes: 0 additions & 3 deletions cryptographic_functions/shamir_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# Shamir three-pass keypair generation
Expand Down
3 changes: 0 additions & 3 deletions cryptographic_functions/shared_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"


# Simple gcd calculation
Expand Down
6 changes: 2 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

if __name__ == '__main__':
#######################
Expand Down Expand Up @@ -50,11 +47,12 @@
rsa_private_key = (rsa_d, rsa_n)
rsa_plaintext = 4
rsa_ciphertext = 31
rsa_p_n = rsa_n // 2 if rsa_n < 50 else 5 # Optional argument

# rsa_calculations.keypair_generation(rsa_p, rsa_q, rsa_e, print_matrix, print_linear_factorization)
# rsa_calculations.encryption(rsa_public_key, rsa_plaintext)
# rsa_calculations.decryption(rsa_private_key, rsa_ciphertext)
# rsa_calculations.brute_force_by_key(rsa_public_key)
rsa_calculations.brute_force_by_key(rsa_public_key, rsa_p_n)

###############################
# Diffie–Hellman initial values
Expand Down

0 comments on commit 84293b6

Please sign in to comment.