Skip to content

Commit

Permalink
Merge pull request #2 from lonkey/release-0.2.1
Browse files Browse the repository at this point in the history
Release 0.2.1
  • Loading branch information
lonkey committed Jan 25, 2021
2 parents b94f665 + 0891afe commit 78691bd
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 29 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Simple Cryptographic Functions
# Simple Cryptographic Algorithms

Python library for demonstrating the functionality of common cryptographic functions.
Python library for demonstrating the functionality of common cryptographic algorithms.

## Requirements

Python 3.7.9 or later including pip for installing the following dependencies:
Python 3.7.9 or later including pip for installing the following requirements:

```shell
pip install -r requirements.txt
```

# Usage
## Usage

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

Expand Down
4 changes: 2 additions & 2 deletions cryptographic_functions/dh_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down
4 changes: 2 additions & 2 deletions cryptographic_functions/elgamal_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down
4 changes: 2 additions & 2 deletions cryptographic_functions/modulo_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down
4 changes: 2 additions & 2 deletions cryptographic_functions/modulo_cyclic_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down
4 changes: 2 additions & 2 deletions cryptographic_functions/modulo_inverse_additive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down
4 changes: 2 additions & 2 deletions cryptographic_functions/modulo_inverse_multiplicative.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down
45 changes: 41 additions & 4 deletions cryptographic_functions/rsa_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down Expand Up @@ -91,7 +91,7 @@ def keypair_generation(p, q, e=None, print_matrix=False, print_linear_factorizat
def encryption(public_key, p):
print(tabulate([['RSA Verschlüsselung']], tablefmt='fancy_grid'))

# Unpack the private key into its components
# Unpack the public key into its components
e, n = public_key

# Choose an integer p such that 0 ≤ p < n
Expand All @@ -116,7 +116,7 @@ def encryption(public_key, p):
def decryption(private_key, c):
print(tabulate([['RSA Entschlüsselung']], tablefmt='fancy_grid'))

# Unpack the public key into its components
# Unpack the private key into its components
d, n = private_key

# Choose an integer c such that 0 ≤ c < n
Expand All @@ -135,3 +135,40 @@ def decryption(private_key, c):
f'p = {c}^{d} mod {n}\n'
f'p = {p}', end='\n\n')
return p


# RSA Brute-force
def brute_force_by_key(any_key):
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)

# Encryption
x_c = (x ** a) % n
y_c = (y ** a) % n
z_c = (z ** a) % n

# 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)

# 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:')
print(tabulate(zip(*(b, [n] * len(b))), headers=['b', 'n'], tablefmt='pretty'), end='\n\n')
return b[0], n
4 changes: 2 additions & 2 deletions cryptographic_functions/shamir_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down
4 changes: 2 additions & 2 deletions cryptographic_functions/shared_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down
11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

__author__ = "Lukas Zorn"
__copyright__ = "Copyright 2021 Lukas Zorn"
__license__ = " GNU GPLv3"
__version__ = "0.1.1"
__license__ = "GNU GPLv3"
__version__ = "0.2.1"
__maintainer__ = "Lukas Zorn"
__status__ = "Development"

Expand Down Expand Up @@ -54,6 +54,7 @@
# 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)

###############################
# Diffie–Hellman initial values
Expand All @@ -65,9 +66,9 @@

# dh_calculations.key_exchange(dh_p, dh_g, dh_a, dh_b)

############################
# Shamir three-pass protocol
############################
###########################################
# Shamir three-pass protocol initial values
###########################################
shamir_p = 23
shamir_a = 3 # Optional argument
shamir_a_i = 15
Expand Down

0 comments on commit 78691bd

Please sign in to comment.