initial commit
This commit is contained in:
commit
0dabde6dad
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.pyc
|
||||||
|
__pycache__
|
23
shark.py
Normal file
23
shark.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user