commit 42b7f5de644e237b309eb0fcb8ab8e670a39ef88 Author: Blue Fox Date: Sat Oct 14 15:56:37 2023 +0200 Initial commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..dc9ea49 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e0e67ca --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/theoEnc.iml b/.idea/theoEnc.iml new file mode 100644 index 0000000..8437fe6 --- /dev/null +++ b/.idea/theoEnc.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/PACKAGE/__init__py b/PACKAGE/__init__py new file mode 100755 index 0000000..e69de29 diff --git a/PACKAGE/build/lib/theoEnc/E2EE.py b/PACKAGE/build/lib/theoEnc/E2EE.py new file mode 100755 index 0000000..b70ebd0 --- /dev/null +++ b/PACKAGE/build/lib/theoEnc/E2EE.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +from .otp import encrypt_otp, decrypt_otp +from .compress import compress, decompress +from .random import random_string + +class E2EE: + def __init__(self, seed: str): + self.seed = seed + self.key = seed + + def get_key(self): + return self.key + + def add_compressed_key_part(self, ckeypart: bytes): + length = len(ckeypart) + ckeypart = decrypt_otp(ckeypart, self.key[length-1:]) + self.key = self.key[length-1:] # delete the used part of the full key + self.key += decompress(ckeypart) + + def generate_compressed_key_part(self, length: int, destroy_used_key=True): + ckeypart = random_string(length) + ckeypart = compress(ckeypart) + ckeypart_enc = encrypt_otp(ckeypart, self.key[len(ckeypart)-1:]) + if destroy_used_key: + self.key = self.key[len(ckeypart)-1:] # delete the of the full key which is used now + return ckeypart_enc + + def addCKeyPart(self, ckeypart: bytes): + self.add_compressed_key_part(ckeypart, length) + def generateCKeyPart(self, length: int, destroy_used_key=True): + self.generate_compressed_key_part(length, destroy_used_key) diff --git a/PACKAGE/build/lib/theoEnc/__init__.py b/PACKAGE/build/lib/theoEnc/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/PACKAGE/build/lib/theoEnc/compress.py b/PACKAGE/build/lib/theoEnc/compress.py new file mode 100755 index 0000000..8be18af --- /dev/null +++ b/PACKAGE/build/lib/theoEnc/compress.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import sys +import zlib +import secrets +import string + +def compress(to_compress: str): + ret = zlib.compress(bytes(to_compress, "ascii"), 9) + return ret + +def decompress(to_decompress: bytes): + ret = zlib.decompress(to_decompress) + return ret.decode("ascii") diff --git a/PACKAGE/build/lib/theoEnc/otp.py b/PACKAGE/build/lib/theoEnc/otp.py new file mode 100755 index 0000000..7c30fc6 --- /dev/null +++ b/PACKAGE/build/lib/theoEnc/otp.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 + +def encrypt_otp(message: bytes, key: str): + if len(message) > len(key): return False; + l = [] + for counter, i in enumerate(message): + l.append(i ^ key.encode()[counter]) + return bytes(l) + +def decrypt_otp(cipher: bytes, key: str): + if len(cipher) > len(key): return False; + l = [] + for counter, i in enumerate(cipher): + l.append(i ^ key.encode()[counter]) + return bytes(l) diff --git a/PACKAGE/build/lib/theoEnc/random.py b/PACKAGE/build/lib/theoEnc/random.py new file mode 100755 index 0000000..1896580 --- /dev/null +++ b/PACKAGE/build/lib/theoEnc/random.py @@ -0,0 +1,11 @@ +#!/usr/bin/python3 + +import secrets +import string + +def random_string(length: int): + symbols = string.punctuation + string.ascii_letters + string.digits + ret = "" + for _ in range(length): + ret += secrets.choice(symbols) + return ret diff --git a/PACKAGE/setup.py b/PACKAGE/setup.py new file mode 100755 index 0000000..03d5229 --- /dev/null +++ b/PACKAGE/setup.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +from __future__ import unicode_literals +from distutils.core import setup + +setup(name='theoEnc', + version='1.0', + description='Library for using the OTP (OneTimePad) in Python3', + author='Benjamin Burkhardt', + packages=['theoEnc']) diff --git a/PACKAGE/theoEnc/E2EE.py b/PACKAGE/theoEnc/E2EE.py new file mode 100755 index 0000000..b70ebd0 --- /dev/null +++ b/PACKAGE/theoEnc/E2EE.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +from .otp import encrypt_otp, decrypt_otp +from .compress import compress, decompress +from .random import random_string + +class E2EE: + def __init__(self, seed: str): + self.seed = seed + self.key = seed + + def get_key(self): + return self.key + + def add_compressed_key_part(self, ckeypart: bytes): + length = len(ckeypart) + ckeypart = decrypt_otp(ckeypart, self.key[length-1:]) + self.key = self.key[length-1:] # delete the used part of the full key + self.key += decompress(ckeypart) + + def generate_compressed_key_part(self, length: int, destroy_used_key=True): + ckeypart = random_string(length) + ckeypart = compress(ckeypart) + ckeypart_enc = encrypt_otp(ckeypart, self.key[len(ckeypart)-1:]) + if destroy_used_key: + self.key = self.key[len(ckeypart)-1:] # delete the of the full key which is used now + return ckeypart_enc + + def addCKeyPart(self, ckeypart: bytes): + self.add_compressed_key_part(ckeypart, length) + def generateCKeyPart(self, length: int, destroy_used_key=True): + self.generate_compressed_key_part(length, destroy_used_key) diff --git a/PACKAGE/theoEnc/__init__.py b/PACKAGE/theoEnc/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/PACKAGE/theoEnc/__pycache__/E2EE.cpython-38.pyc b/PACKAGE/theoEnc/__pycache__/E2EE.cpython-38.pyc new file mode 100755 index 0000000..e2d6d8c Binary files /dev/null and b/PACKAGE/theoEnc/__pycache__/E2EE.cpython-38.pyc differ diff --git a/PACKAGE/theoEnc/__pycache__/__init__.cpython-38.pyc b/PACKAGE/theoEnc/__pycache__/__init__.cpython-38.pyc new file mode 100755 index 0000000..8edde65 Binary files /dev/null and b/PACKAGE/theoEnc/__pycache__/__init__.cpython-38.pyc differ diff --git a/PACKAGE/theoEnc/__pycache__/compress.cpython-38.pyc b/PACKAGE/theoEnc/__pycache__/compress.cpython-38.pyc new file mode 100755 index 0000000..39e85ea Binary files /dev/null and b/PACKAGE/theoEnc/__pycache__/compress.cpython-38.pyc differ diff --git a/PACKAGE/theoEnc/__pycache__/otp.cpython-38.pyc b/PACKAGE/theoEnc/__pycache__/otp.cpython-38.pyc new file mode 100755 index 0000000..2c4d25c Binary files /dev/null and b/PACKAGE/theoEnc/__pycache__/otp.cpython-38.pyc differ diff --git a/PACKAGE/theoEnc/__pycache__/random.cpython-38.pyc b/PACKAGE/theoEnc/__pycache__/random.cpython-38.pyc new file mode 100755 index 0000000..8be75a6 Binary files /dev/null and b/PACKAGE/theoEnc/__pycache__/random.cpython-38.pyc differ diff --git a/PACKAGE/theoEnc/compress.py b/PACKAGE/theoEnc/compress.py new file mode 100755 index 0000000..8be18af --- /dev/null +++ b/PACKAGE/theoEnc/compress.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import sys +import zlib +import secrets +import string + +def compress(to_compress: str): + ret = zlib.compress(bytes(to_compress, "ascii"), 9) + return ret + +def decompress(to_decompress: bytes): + ret = zlib.decompress(to_decompress) + return ret.decode("ascii") diff --git a/PACKAGE/theoEnc/otp.py b/PACKAGE/theoEnc/otp.py new file mode 100755 index 0000000..7c30fc6 --- /dev/null +++ b/PACKAGE/theoEnc/otp.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 + +def encrypt_otp(message: bytes, key: str): + if len(message) > len(key): return False; + l = [] + for counter, i in enumerate(message): + l.append(i ^ key.encode()[counter]) + return bytes(l) + +def decrypt_otp(cipher: bytes, key: str): + if len(cipher) > len(key): return False; + l = [] + for counter, i in enumerate(cipher): + l.append(i ^ key.encode()[counter]) + return bytes(l) diff --git a/PACKAGE/theoEnc/random.py b/PACKAGE/theoEnc/random.py new file mode 100755 index 0000000..1896580 --- /dev/null +++ b/PACKAGE/theoEnc/random.py @@ -0,0 +1,11 @@ +#!/usr/bin/python3 + +import secrets +import string + +def random_string(length: int): + symbols = string.punctuation + string.ascii_letters + string.digits + ret = "" + for _ in range(length): + ret += secrets.choice(symbols) + return ret diff --git a/client.py b/client.py new file mode 100755 index 0000000..e2e29ac --- /dev/null +++ b/client.py @@ -0,0 +1,12 @@ +#!/usr/bin/python3 + +from theoEnc.E2EE import E2EE + +seed = input("Seed: ") + +e2ee = E2EE(seed) + +while True: + ckeypart = input("Neuer Schlüsselteil: ").encode() + e2ee.add_compressed_key_part(ckeypart, 10) + print("\nKey: " + e2ee.get_key()) diff --git a/server.py b/server.py new file mode 100755 index 0000000..8d7457c --- /dev/null +++ b/server.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +from theoEnc.E2EE import E2EE +from theoEnc.random import random_string + +seed = random_string(20) +print("Seed: " + seed) + +e2ee = E2EE(seed) + +while True: + input("Neuer Schlüsselteil: [ENTER] ") + ckeypart = e2ee.generate_compressed_key_part(10) + print("\nKey: " + e2ee.get_key() + "\nNeuer kompressierter Schlüsselteil: " + ckeypart.decode()) diff --git a/test.py b/test.py new file mode 100755 index 0000000..52b2d46 --- /dev/null +++ b/test.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +from theoEnc.E2EE import E2EE +from theoEnc.random import random_string + +LEN = 499900 + + +seed = random_string(500000) +print("[SERVER] Length of Seed: " + str(len(seed))) + +e2ee_server = E2EE(seed) +e2ee_client = E2EE(seed) + +print("\n[SERVER] Generating new compressed key part (CKP)...") +ckp = e2ee_server.generate_compressed_key_part(LEN, destroy_used_key=False) +e2ee_server.add_compressed_key_part(ckp) +print("[SERVER] Generated.") +print("[SERVER] Length of Key: " + str(len(e2ee_server.get_key()))) + +print("[CLIENT] Adding CCP...") +e2ee_client.add_compressed_key_part(ckp) +print("[CLIENT] Added.") +print("[CLIENT] Length of Key: " + str(len(e2ee_client.get_key()))) diff --git a/theoEnc/E2EE.py b/theoEnc/E2EE.py new file mode 100755 index 0000000..b70ebd0 --- /dev/null +++ b/theoEnc/E2EE.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +from .otp import encrypt_otp, decrypt_otp +from .compress import compress, decompress +from .random import random_string + +class E2EE: + def __init__(self, seed: str): + self.seed = seed + self.key = seed + + def get_key(self): + return self.key + + def add_compressed_key_part(self, ckeypart: bytes): + length = len(ckeypart) + ckeypart = decrypt_otp(ckeypart, self.key[length-1:]) + self.key = self.key[length-1:] # delete the used part of the full key + self.key += decompress(ckeypart) + + def generate_compressed_key_part(self, length: int, destroy_used_key=True): + ckeypart = random_string(length) + ckeypart = compress(ckeypart) + ckeypart_enc = encrypt_otp(ckeypart, self.key[len(ckeypart)-1:]) + if destroy_used_key: + self.key = self.key[len(ckeypart)-1:] # delete the of the full key which is used now + return ckeypart_enc + + def addCKeyPart(self, ckeypart: bytes): + self.add_compressed_key_part(ckeypart, length) + def generateCKeyPart(self, length: int, destroy_used_key=True): + self.generate_compressed_key_part(length, destroy_used_key) diff --git a/theoEnc/__init__.py b/theoEnc/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/theoEnc/__pycache__/E2EE.cpython-310.pyc b/theoEnc/__pycache__/E2EE.cpython-310.pyc new file mode 100644 index 0000000..00e36c4 Binary files /dev/null and b/theoEnc/__pycache__/E2EE.cpython-310.pyc differ diff --git a/theoEnc/__pycache__/E2EE.cpython-38.pyc b/theoEnc/__pycache__/E2EE.cpython-38.pyc new file mode 100755 index 0000000..e2d6d8c Binary files /dev/null and b/theoEnc/__pycache__/E2EE.cpython-38.pyc differ diff --git a/theoEnc/__pycache__/__init__.cpython-310.pyc b/theoEnc/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..a15d68a Binary files /dev/null and b/theoEnc/__pycache__/__init__.cpython-310.pyc differ diff --git a/theoEnc/__pycache__/__init__.cpython-38.pyc b/theoEnc/__pycache__/__init__.cpython-38.pyc new file mode 100755 index 0000000..8edde65 Binary files /dev/null and b/theoEnc/__pycache__/__init__.cpython-38.pyc differ diff --git a/theoEnc/__pycache__/compress.cpython-310.pyc b/theoEnc/__pycache__/compress.cpython-310.pyc new file mode 100644 index 0000000..7327e14 Binary files /dev/null and b/theoEnc/__pycache__/compress.cpython-310.pyc differ diff --git a/theoEnc/__pycache__/compress.cpython-38.pyc b/theoEnc/__pycache__/compress.cpython-38.pyc new file mode 100755 index 0000000..39e85ea Binary files /dev/null and b/theoEnc/__pycache__/compress.cpython-38.pyc differ diff --git a/theoEnc/__pycache__/otp.cpython-310.pyc b/theoEnc/__pycache__/otp.cpython-310.pyc new file mode 100644 index 0000000..110ac16 Binary files /dev/null and b/theoEnc/__pycache__/otp.cpython-310.pyc differ diff --git a/theoEnc/__pycache__/otp.cpython-38.pyc b/theoEnc/__pycache__/otp.cpython-38.pyc new file mode 100755 index 0000000..2c4d25c Binary files /dev/null and b/theoEnc/__pycache__/otp.cpython-38.pyc differ diff --git a/theoEnc/__pycache__/random.cpython-310.pyc b/theoEnc/__pycache__/random.cpython-310.pyc new file mode 100644 index 0000000..2a2d0a5 Binary files /dev/null and b/theoEnc/__pycache__/random.cpython-310.pyc differ diff --git a/theoEnc/__pycache__/random.cpython-38.pyc b/theoEnc/__pycache__/random.cpython-38.pyc new file mode 100755 index 0000000..8be75a6 Binary files /dev/null and b/theoEnc/__pycache__/random.cpython-38.pyc differ diff --git a/theoEnc/compress.py b/theoEnc/compress.py new file mode 100755 index 0000000..8be18af --- /dev/null +++ b/theoEnc/compress.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import sys +import zlib +import secrets +import string + +def compress(to_compress: str): + ret = zlib.compress(bytes(to_compress, "ascii"), 9) + return ret + +def decompress(to_decompress: bytes): + ret = zlib.decompress(to_decompress) + return ret.decode("ascii") diff --git a/theoEnc/otp.py b/theoEnc/otp.py new file mode 100755 index 0000000..7c30fc6 --- /dev/null +++ b/theoEnc/otp.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 + +def encrypt_otp(message: bytes, key: str): + if len(message) > len(key): return False; + l = [] + for counter, i in enumerate(message): + l.append(i ^ key.encode()[counter]) + return bytes(l) + +def decrypt_otp(cipher: bytes, key: str): + if len(cipher) > len(key): return False; + l = [] + for counter, i in enumerate(cipher): + l.append(i ^ key.encode()[counter]) + return bytes(l) diff --git a/theoEnc/random.py b/theoEnc/random.py new file mode 100755 index 0000000..1896580 --- /dev/null +++ b/theoEnc/random.py @@ -0,0 +1,11 @@ +#!/usr/bin/python3 + +import secrets +import string + +def random_string(length: int): + symbols = string.punctuation + string.ascii_letters + string.digits + ret = "" + for _ in range(length): + ret += secrets.choice(symbols) + return ret