From 1ea46419ca7e2ce58fff1bbd5b0761a2020dac2f Mon Sep 17 00:00:00 2001 From: David Huh <38101884+qt1337@users.noreply.github.com> Date: Mon, 18 Oct 2021 11:42:09 +0200 Subject: [PATCH 1/2] :sparkles: Added comments and bruteforce example --- Verschiebe-Chiffre.py | 58 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/Verschiebe-Chiffre.py b/Verschiebe-Chiffre.py index 1dfbfad..34cb9a8 100644 --- a/Verschiebe-Chiffre.py +++ b/Verschiebe-Chiffre.py @@ -1,13 +1,48 @@ def encrypt_text(cleartext: str = 'Bitcoin', incrementation: int = 13): - encrypted_text = '' + """ + This method encrypts a text by shifting each letter by the value of incrementation + + :param cleartext: The secret message to encrypt + :param incrementation: How much the letters should be shifted + :return: Encrypted text + """ + return shift_text(cleartext, (incrementation % 26)) # '%' to repeat after 26 with 0 + + +def decrypt_text(encrypted_text: str = 'Ovgpbva', incrementation: int = 13): + """ + This method decrypts a text by shifting each letter by the value of incrementation + + :param encrypted_text: The encrypted secret message to decrypt + :param incrementation: How much the letters should be shifted + :return: Decrypted text + """ + return shift_text(encrypted_text, 26 - (incrementation % 26)) # '%' to repeat after 26 with 0 + + +def shift_text(cleartext: str, incrementation: int): + """ + This method shifts every letter of a string by the value of incrementation + :param cleartext: The string to be shifted + :param incrementation: How much the letters should be shifted + :return: Shifted text + """ + shifted_text = '' for char in cleartext: - encrypted_text += increment_char(char, incrementation) + shifted_text += increment_char(char, incrementation) - return encrypted_text + return shifted_text def increment_char(char, incrementation: int = 1): + """ + This method shifts one char by the value of incrementation + + :param char: Char to be shifted + :param incrementation: How much the char should be shifted + :return: Shifted letter + """ # converting character to byte char_in_bytes = bytes(char, 'utf-8')[0] if char_in_bytes + incrementation >= 91 and char_in_bytes < 91 \ @@ -19,15 +54,22 @@ def increment_char(char, incrementation: int = 1): return str(new_char_in_bytes)[2] -def decrypt_text(encrypted_text: str = 'Ovgpbva', incrementation: int = 13): - cleartext = '' +def brute_force_example(cleartext: str = 'Bitcoin', incrementation: int = 7): + """ + This is an example of how to bruteforce an encrypted text. (Encrypted with Letter-Shifting) - for char in encrypted_text: - cleartext += increment_char(char, 26 - incrementation) + :param cleartext: The secret message to encrypt and decrypt during bruteforcing + :param incrementation: How much the letters should be shifted + """ + encrypted_text = encrypt_text(cleartext, incrementation=incrementation) - return cleartext + for x in range(26): + if cleartext == decrypt_text(encrypted_text, incrementation=x): + print(f'Text was shifted by {x} letters.') if __name__ == '__main__': print(encrypt_text()) print(decrypt_text()) + + brute_force_example() From fbf2c08ff73700cd1e5f1fa4c22a984e1499777a Mon Sep 17 00:00:00 2001 From: David Huh <38101884+qt1337@users.noreply.github.com> Date: Mon, 18 Oct 2021 11:42:55 +0200 Subject: [PATCH 2/2] :truck: Moved Verschiebe-Chiffre.py to chapter one --- Verschiebe-Chiffre.py => chapter_one/Verschiebe-Chiffre.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Verschiebe-Chiffre.py => chapter_one/Verschiebe-Chiffre.py (100%) diff --git a/Verschiebe-Chiffre.py b/chapter_one/Verschiebe-Chiffre.py similarity index 100% rename from Verschiebe-Chiffre.py rename to chapter_one/Verschiebe-Chiffre.py