24 lines
797 B
Python
24 lines
797 B
Python
|
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)
|