From d087abd7e67e095f16ef5654be9504182013aec2 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 2 Jun 2023 11:14:46 +0200 Subject: [PATCH] oaep finish --- src-py/plexcryptool/scripts/common.py | 29 +++++++++++++++++++ .../plexcryptool/scripts/oaep-ciphertext.txt | 1 + src-py/plexcryptool/scripts/oaep_rsa.py | 5 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src-py/plexcryptool/scripts/common.py create mode 100644 src-py/plexcryptool/scripts/oaep-ciphertext.txt diff --git a/src-py/plexcryptool/scripts/common.py b/src-py/plexcryptool/scripts/common.py new file mode 100644 index 0000000..1c7a8ae --- /dev/null +++ b/src-py/plexcryptool/scripts/common.py @@ -0,0 +1,29 @@ +""" +Common tools that may be used by many + +@author: Christoph J. Scherr +@license: MIT +@source: https://git.cscherr.de/PlexSheep/plexcryptool/src/branch/master/plexcryptool/trash-hash.py +""" + +from math import floor + +def byte_xor(ba0: bytearray, ba1: bytearray) -> bytearray: + """ + helper function for bytewise xor + """ + ba2: bytearray = bytearray(0) + for (b0, b1) in zip(ba0, ba1): + ba2.append((b0 ^ b1)) + #print("xored:\n%s" % ba2.hex()) + return ba2 + +def calc_byte_len(n: int) -> int: + """ + helper function to calculate the length in bytes + """ + len = n.bit_length() / 8 + if len > floor(len): + return 1 + floor(len) + else: + return floor(len) diff --git a/src-py/plexcryptool/scripts/oaep-ciphertext.txt b/src-py/plexcryptool/scripts/oaep-ciphertext.txt new file mode 100644 index 0000000..b147ec6 --- /dev/null +++ b/src-py/plexcryptool/scripts/oaep-ciphertext.txt @@ -0,0 +1 @@ +0976f89569d94414fed4f7714cd85c840dbf338781926f5d1f6284688c97eaeef7f42b3d844c70468cfb960092235855da5d5c66107dfee4204c1a78512ee00306da957a856a085affe40b2ab32fc90a8c8e059feea9a83e753618aeae04884aa1658afe59a69c30ec5c014a5da06ff484143ca1ea884b44a3f92d063db8503f diff --git a/src-py/plexcryptool/scripts/oaep_rsa.py b/src-py/plexcryptool/scripts/oaep_rsa.py index c5a465d..af8fe46 100755 --- a/src-py/plexcryptool/scripts/oaep_rsa.py +++ b/src-py/plexcryptool/scripts/oaep_rsa.py @@ -79,7 +79,7 @@ def mgf1(seed: bytearray, length: int, hash_func=hashlib.sha256) -> bytearray: # 4.Output the leading l octets of T as the octet string mask. return bytearray(T[:length]) -def byte_xor(ba0: bytearray, ba1: bytearray): +def byte_xor(ba0: bytearray, ba1: bytearray) -> bytearray: """ helper function for bytewise xor """ @@ -203,7 +203,8 @@ def main(): else: ha = bytearray(0) if args.message: - m = bytearray.fromhex(args.message) + m = bytearray(str.encode(args.message)) + print("msg: %s" % m.hex()) else: m = bytearray.fromhex("466f6f62617220313233343536373839") if args.seed: