77
88__author__ = "Lukas Zorn"
99__copyright__ = "Copyright 2021 Lukas Zorn"
10- __license__ = " GNU GPLv3"
11- __version__ = "0.1 .1"
10+ __license__ = "GNU GPLv3"
11+ __version__ = "0.2 .1"
1212__maintainer__ = "Lukas Zorn"
1313__status__ = "Development"
1414
@@ -91,7 +91,7 @@ def keypair_generation(p, q, e=None, print_matrix=False, print_linear_factorizat
9191def encryption (public_key , p ):
9292 print (tabulate ([['RSA Verschlüsselung' ]], tablefmt = 'fancy_grid' ))
9393
94- # Unpack the private key into its components
94+ # Unpack the public key into its components
9595 e , n = public_key
9696
9797 # Choose an integer p such that 0 ≤ p < n
@@ -116,7 +116,7 @@ def encryption(public_key, p):
116116def decryption (private_key , c ):
117117 print (tabulate ([['RSA Entschlüsselung' ]], tablefmt = 'fancy_grid' ))
118118
119- # Unpack the public key into its components
119+ # Unpack the private key into its components
120120 d , n = private_key
121121
122122 # Choose an integer c such that 0 ≤ c < n
@@ -135,3 +135,40 @@ def decryption(private_key, c):
135135 f'p = { c } ^{ d } mod { n } \n '
136136 f'p = { p } ' , end = '\n \n ' )
137137 return p
138+
139+
140+ # RSA Brute-force
141+ def brute_force_by_key (any_key ):
142+ print (tabulate ([['RSA Brute-Force Angriff (schlüsselbasiert)' ]], tablefmt = 'fancy_grid' ))
143+
144+ # Unpack the key into its components
145+ a , n = any_key
146+
147+ # Choose multiple integers x such that 0 ≤ x < n
148+ x , y , z = random .sample (range (n ), 3 )
149+
150+ # Encryption
151+ x_c = (x ** a ) % n
152+ y_c = (y ** a ) % n
153+ z_c = (z ** a ) % n
154+
155+ # Brute-force
156+ b = []
157+ for v in range (n ):
158+ if x != (x_c ** v ) % n :
159+ continue
160+ if y != (y_c ** v ) % n :
161+ continue
162+ if z != (z_c ** v ) % n :
163+ continue
164+ b .append (v )
165+
166+ # Calculation path output
167+ if len (b ) < 1 :
168+ print (
169+ f'Das Gegenstück für den Schlüssel K = {{{ a } , { n } }} konnte nicht ermittelt werden.' , end = '\n \n ' )
170+ return - 1
171+ print (
172+ f'Mögliche Gegenstücke für den Schlüssel K = {{{ a } , { n } }} mit den Testwerten x = { x } , y = { y } und z = { z } sind:' )
173+ print (tabulate (zip (* (b , [n ] * len (b ))), headers = ['b' , 'n' ], tablefmt = 'pretty' ), end = '\n \n ' )
174+ return b [0 ], n
0 commit comments