Initial commit
This commit is contained in:
0
PACKAGE/__init__py
Executable file
0
PACKAGE/__init__py
Executable file
32
PACKAGE/build/lib/theoEnc/E2EE.py
Executable file
32
PACKAGE/build/lib/theoEnc/E2EE.py
Executable file
@@ -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)
|
0
PACKAGE/build/lib/theoEnc/__init__.py
Executable file
0
PACKAGE/build/lib/theoEnc/__init__.py
Executable file
14
PACKAGE/build/lib/theoEnc/compress.py
Executable file
14
PACKAGE/build/lib/theoEnc/compress.py
Executable file
@@ -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")
|
15
PACKAGE/build/lib/theoEnc/otp.py
Executable file
15
PACKAGE/build/lib/theoEnc/otp.py
Executable file
@@ -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)
|
11
PACKAGE/build/lib/theoEnc/random.py
Executable file
11
PACKAGE/build/lib/theoEnc/random.py
Executable file
@@ -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
|
10
PACKAGE/setup.py
Executable file
10
PACKAGE/setup.py
Executable file
@@ -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'])
|
32
PACKAGE/theoEnc/E2EE.py
Executable file
32
PACKAGE/theoEnc/E2EE.py
Executable file
@@ -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)
|
0
PACKAGE/theoEnc/__init__.py
Executable file
0
PACKAGE/theoEnc/__init__.py
Executable file
BIN
PACKAGE/theoEnc/__pycache__/E2EE.cpython-38.pyc
Executable file
BIN
PACKAGE/theoEnc/__pycache__/E2EE.cpython-38.pyc
Executable file
Binary file not shown.
BIN
PACKAGE/theoEnc/__pycache__/__init__.cpython-38.pyc
Executable file
BIN
PACKAGE/theoEnc/__pycache__/__init__.cpython-38.pyc
Executable file
Binary file not shown.
BIN
PACKAGE/theoEnc/__pycache__/compress.cpython-38.pyc
Executable file
BIN
PACKAGE/theoEnc/__pycache__/compress.cpython-38.pyc
Executable file
Binary file not shown.
BIN
PACKAGE/theoEnc/__pycache__/otp.cpython-38.pyc
Executable file
BIN
PACKAGE/theoEnc/__pycache__/otp.cpython-38.pyc
Executable file
Binary file not shown.
BIN
PACKAGE/theoEnc/__pycache__/random.cpython-38.pyc
Executable file
BIN
PACKAGE/theoEnc/__pycache__/random.cpython-38.pyc
Executable file
Binary file not shown.
14
PACKAGE/theoEnc/compress.py
Executable file
14
PACKAGE/theoEnc/compress.py
Executable file
@@ -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")
|
15
PACKAGE/theoEnc/otp.py
Executable file
15
PACKAGE/theoEnc/otp.py
Executable file
@@ -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)
|
11
PACKAGE/theoEnc/random.py
Executable file
11
PACKAGE/theoEnc/random.py
Executable file
@@ -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
|
Reference in New Issue
Block a user