From 0dabde6dad3efa7ade8583e930f9cefa9b5e81e6 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Mon, 20 Sep 2021 11:32:55 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 ++ README.md | 0 shark.py | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 shark.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a295864 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +__pycache__ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/shark.py b/shark.py new file mode 100644 index 0000000..ea0f162 --- /dev/null +++ b/shark.py @@ -0,0 +1,23 @@ +import hashlib +import math + +# Shark is a sha256+xor based encryption. +# I made it because I want to try to break it. +# (Precisely: Show it does not provide semantic security, because it is not IND-CPA-secure) +# This will work iff I succeed in building a PPT-discriminator for sha256 from randomness +# As my first approach this discriminator will be based on an LSTM-network. + +def xor(ta,tb): + return bytes(a ^ b for a, b in zip(ta, tb)) + +def enc(plaintext, key, iv): + ciphertext = bytes() + bs = 256/8 + for i in range(math.ceil(len(plaintext/bs))): + m = hashlib.sha256() + m.update(xor(key, iv + i.to_bytes(bs, byteorder='big'))) + k = m.digest() + ciphertext += sxor(k, plaintext[bs*i:][:bs]) + +def dec(ciphertext, key, iv): + return enc(ciphertext, key, iv)