Update the cracking for S-DES to remove the wrong decoded texts.
continuous-integration/drone/push Build is passing Details

main
KKlochko 1 year ago
parent 8cbd5d5c1f
commit 8a914a741d

@ -5,7 +5,7 @@ from rich.prompt import Prompt
from cryptography_s_des_exploring.sdes.decrypt import decrypt_block
from cryptography_s_des_exploring.sdes.blocks import decode, decode_bytes
from cryptography_s_des_exploring.sdes.blocks import encode, decode, decode_bytes
def cast_to_key(number: int):
@ -18,15 +18,19 @@ def cracking(ciphertext):
start = time.monotonic()
decoded_ciphertext = list(decode_bytes(ciphertext))
for n in range(0, 1024):
key = cast_to_key(n)
decoded = decode_bytes(ciphertext)
decrypted = list(map(lambda b: decrypt_block(key, b), decoded))
decrypted = list(map(lambda b: decrypt_block(key, b), decoded_ciphertext))
try:
decoded = decode(decrypted)
founded.append((key, decoded))
decoded_text = decode(decrypted)
if len(decrypted) == len(list(encode(decoded_text))):
founded.append((key, decoded_text))
except UnicodeDecodeError as e:
continue
except binascii.Error as e:

Loading…
Cancel
Save