Created
October 22, 2017 20:04
-
-
Save grocid/8118791134dd620cbf7cc009a18c5f71 to your computer and use it in GitHub Desktop.
mceliece reed-solomon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_a(alpha, G, j): | |
i = GF.fetch_int(1) | |
k = G.nrows() | |
if k <= j: | |
return i / (i - (i/alpha) * G[0][j]/G[1][j] ) | |
else: | |
return i / (i - (i/alpha) * (G[j][k+1]/G[1][k+1] - G[j][k]/G[1][k]) \ | |
/ (G[j][k+1]/G[0][k+1] - G[j][k]/G[0][k])) | |
def crack(A): | |
A = vector(A) | |
C = codes.GeneralizedReedSolomonCode(A, k) | |
D = codes.decoders.GRSBerlekampWelchDecoder(C) | |
return D.decode_to_code(ciphertext) | |
pub = load('publickey.sobj') | |
ciphertext = load('ciphertext.sobj') | |
pubsys = pub.echelon_form() | |
GF = parent(pub[0][0]) | |
n = pubsys.ncols() | |
k = pubsys.nrows() | |
for alpha in range(0, 256): | |
if alpha == pub[1][j]/pub[0][j]: | |
continue | |
try: | |
A = [0, 1] + [get_a(GF.fetch_int(alpha), pubsys, j) for j in range(2, n)] | |
cc = crack(A) | |
m = pub.solve_left(cc) | |
print ''.join(chr(mc.integer_representation()) for mc in m) | |
break | |
except Exception as e: | |
print e | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment