Add files via upload
This commit is contained in:
parent
e992166bf0
commit
c2be250e4f
3 changed files with 11 additions and 4 deletions
3
break.py
3
break.py
|
@ -47,12 +47,13 @@ def decode(S, P, c):
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def break_S(P, G_):
|
def break_S(P, G_):
|
||||||
|
return my_fix(G_ @ np.linalg.inv(P)) #works for Reed-Solomon
|
||||||
#G_ = S @ G @ P
|
#G_ = S @ G @ P
|
||||||
rs = galois.ReedSolomon(n, k, field=GF)
|
rs = galois.ReedSolomon(n, k, field=GF)
|
||||||
G = rs.G
|
G = rs.G
|
||||||
G_ = G_ @ np.linalg.inv(P)
|
G_ = G_ @ np.linalg.inv(P)
|
||||||
G_ = my_fix(G_)
|
G_ = my_fix(G_)
|
||||||
G = my_fix(G)
|
G = my_fix(G) #returns E because we use Reed-Solomon algo
|
||||||
S = G_ @ np.linalg.inv(G)
|
S = G_ @ np.linalg.inv(G)
|
||||||
return S
|
return S
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import galois
|
import galois
|
||||||
|
import random
|
||||||
|
|
||||||
import pubkey
|
import pubkey
|
||||||
|
|
||||||
|
@ -28,7 +29,12 @@ def encrypt(G_, text):
|
||||||
msg = pad_message(text.encode(), k)
|
msg = pad_message(text.encode(), k)
|
||||||
m = GF(msg)
|
m = GF(msg)
|
||||||
c = m.T @ G_
|
c = m.T @ G_
|
||||||
return c
|
t = (n - k) // 2
|
||||||
|
z = np.zeros(n, dtype = int)
|
||||||
|
p = [i for i in range(n)]
|
||||||
|
for i in range(t):
|
||||||
|
z[p.pop(random.randint(0, n - 1 - i))] = random.randint(0, order - 1)
|
||||||
|
return c + GF(z)
|
||||||
|
|
||||||
def export(ct):
|
def export(ct):
|
||||||
output = "ct = [ " + ", ".join([str(int(cell)) for cell in ct]) + " ]"
|
output = "ct = [ " + ", ".join([str(int(cell)) for cell in ct]) + " ]"
|
||||||
|
|
|
@ -12,5 +12,5 @@ Check break.py to understand how hacker can do this.
|
||||||
|
|
||||||
todo:
|
todo:
|
||||||
1. left part of G is E, because we use Reed-Solomon algo; so left part of S @ G is S and cutting right colomns works; my_fix(G) returns E and in break_S we needn't get inv(G), just S = my_fix(G_ @ inv(P)), check it; try break_S with another (not Reed-Solomon) code (matrix G will be different; will my_fix(G) and my_fix(G_) return nonsingular matrices?; of course, rank(G) = rank(G_) = k and we can iterate through all possible combinations of column deletions and find one that does not lead to nonsingular matrices); another way to get S is calculating it row by row (solving k systems, each has n equations with k variables, k < n, but we need to do it in Galois Field)
|
1. left part of G is E, because we use Reed-Solomon algo; so left part of S @ G is S and cutting right colomns works; my_fix(G) returns E and in break_S we needn't get inv(G), just S = my_fix(G_ @ inv(P)), check it; try break_S with another (not Reed-Solomon) code (matrix G will be different; will my_fix(G) and my_fix(G_) return nonsingular matrices?; of course, rank(G) = rank(G_) = k and we can iterate through all possible combinations of column deletions and find one that does not lead to nonsingular matrices); another way to get S is calculating it row by row (solving k systems, each has n equations with k variables, k < n, but we need to do it in Galois Field)
|
||||||
2. check randomization during encode (add vector z, check https://en.wikipedia.org/wiki/McEliece_cryptosystem)
|
2. DONE! check randomization during encode (add vector z, check https://en.wikipedia.org/wiki/McEliece_cryptosystem)
|
||||||
3. make presentation that explains McEliece cryptosystem
|
3. DONE! make presentation that explains McEliece cryptosystem
|
Loading…
Reference in a new issue