From 8c63cedfa47b6c8cd5183eb8cfd96faa477f6e26 Mon Sep 17 00:00:00 2001 From: David Huh <38101884+qt1337@users.noreply.github.com> Date: Fri, 15 Oct 2021 13:29:56 +0200 Subject: [PATCH] :construction: WIP --- Verschiebe-Chiffre.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Verschiebe-Chiffre.py diff --git a/Verschiebe-Chiffre.py b/Verschiebe-Chiffre.py new file mode 100644 index 0000000..1dfbfad --- /dev/null +++ b/Verschiebe-Chiffre.py @@ -0,0 +1,33 @@ +def encrypt_text(cleartext: str = 'Bitcoin', incrementation: int = 13): + encrypted_text = '' + + for char in cleartext: + encrypted_text += increment_char(char, incrementation) + + return encrypted_text + + +def increment_char(char, incrementation: int = 1): + # converting character to byte + char_in_bytes = bytes(char, 'utf-8')[0] + if char_in_bytes + incrementation >= 91 and char_in_bytes < 91 \ + or char_in_bytes + incrementation >= 123: # z -> 122 | 90 -> Z so go backwards + new_char_in_bytes = bytes([char_in_bytes - (26 - incrementation)]) + else: + new_char_in_bytes = bytes([char_in_bytes + incrementation]) + + return str(new_char_in_bytes)[2] + + +def decrypt_text(encrypted_text: str = 'Ovgpbva', incrementation: int = 13): + cleartext = '' + + for char in encrypted_text: + cleartext += increment_char(char, 26 - incrementation) + + return cleartext + + +if __name__ == '__main__': + print(encrypt_text()) + print(decrypt_text())