Compare commits

...
8 Commits
5 changed files with 21 additions and 17 deletions
+2 -1
View File
@@ -6,4 +6,5 @@ I made it because I want to try to break it.
This will work iff I succeed in building a PPT-discriminator for sha256 from randomness 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. As my first approach this discriminator will be based on an LSTM-network.
Update: This worked out way better than expected; given long enought sequences (128 Bytes are more than enough) we can discriminate successfully in 100% of cases. Update: This worked out way better than expected; given long enought sequences (128 Bytes are more than enough) we can discriminate successfully in 100% of cases.
Update: I did an upsie in the training-code and the discriminator is actually shit. Update 2: I did an upsie in the training-code and the discriminator is actually shit.
Update 3: Turns out: sha256 produces fairly high quality randomness and this project seems to have failed...
+1 -1
View File
@@ -10,7 +10,7 @@ import random
import shark import shark
from model import Model from model import Model
bs = int(256/8) bs = shark.bs
class Model(nn.Module): class Model(nn.Module):
def __init__(self): def __init__(self):
+2
View File
@@ -3,6 +3,8 @@ from torch import nn
from torch import nn, optim from torch import nn, optim
from torch.utils.data import DataLoader from torch.utils.data import DataLoader
import shark
class Model(nn.Module): class Model(nn.Module):
def __init__(self): def __init__(self):
super(Model, self).__init__() super(Model, self).__init__()
-6
View File
@@ -3,12 +3,6 @@ import math
import os import os
import random import random
# 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.
bs = int(256/8) bs = int(256/8)
def xor(ta,tb): def xor(ta,tb):
+14 -7
View File
@@ -9,11 +9,11 @@ import math
import shark import shark
from model import Model from model import Model
def train(model, seq_len=16*64): def train(model, seq_len=16*256): # 0.5KiB
tid = str(int(random.random()*99999)).zfill(5) tid = str(int(random.random()*99999)).zfill(5)
print("[i] I am "+str(tid)) print("[i] I am "+str(tid))
ltLoss = 50 ltLoss = 0.75
lltLoss = 52 lltLoss = 0.80
model.train() model.train()
criterion = nn.BCELoss() criterion = nn.BCELoss()
@@ -23,13 +23,15 @@ def train(model, seq_len=16*64):
state_c = [None,None] state_c = [None,None]
blob = [None,None] blob = [None,None]
correct = [None,None] correct = [None,None]
err = [None,None]
ltErr = 0.5
for epoch in range(1024): for epoch in range(1024):
state_h[0], state_c[0] = model.init_state(seq_len) state_h[0], state_c[0] = model.init_state(seq_len)
state_h[1], state_c[1] = model.init_state(seq_len) state_h[1], state_c[1] = model.init_state(seq_len)
blob[0], _ = shark.getSample(min(seq_len, 16*(epoch+1)), 0) blob[0], _ = shark.getSample(seq_len, 0)
blob[1], _ = shark.getSample(min(seq_len, 16*(epoch+1)), 1) blob[1], _ = shark.getSample(seq_len, 1)
optimizer.zero_grad() optimizer.zero_grad()
for i in range(len(blob[0])): for i in range(len(blob[0])):
for t in range(2): for t in range(2):
@@ -44,11 +46,16 @@ def train(model, seq_len=16*64):
optimizer.step() optimizer.step()
correct[t] = round(y_pred.item()) == t correct[t] = round(y_pred.item()) == t
err[t] = abs(t - y_pred.item())
ltLoss = ltLoss*0.9 + 0.1*loss.item() ltLoss = ltLoss*0.9 + 0.1*loss.item()
ltErr = ltErr*0.99 + (err[0] + err[1])*0.005
lltLoss = lltLoss*0.9 + 0.1*ltLoss lltLoss = lltLoss*0.9 + 0.1*ltLoss
print({ 'epoch': epoch, 'loss': loss.item(), 'ltLoss': ltLoss, 'ok0': correct[0], 'ok1': correct[1], 'succ': correct[0] and correct[1], 'acc': str(int(max(0, 1-math.sqrt(lltLoss))*100))+"%" }) print({ 'epoch': epoch, 'loss': loss.item(), 'lltLoss': lltLoss, 'ok0': correct[0], 'ok1': correct[1], 'succ': correct[0] and correct[1], 'acc': str(int(100-(err[0]+err[1])*50))+"%" })
if epoch % 8 == 0:
torch.save(model.state_dict(), 'model_savepoints/'+tid+'_'+str(epoch)+'.n') torch.save(model.state_dict(), 'model_savepoints/'+tid+'_'+str(epoch)+'.n')
if 0.45 < ltErr < 0.55:
print("[~] My emperor! I've failed! A BARREL ROLL!")
else:
print("[~] Booyaaa!!!!")
model = Model() model = Model()