Last active
August 29, 2015 14:05
-
-
Save nuit/33bcbc0499127e673329 to your computer and use it in GitHub Desktop.
inverse matrix encryption
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
import string | |
import numpy as np | |
from numpy.linalg import inv | |
M = [[7,18,5], | |
[1,20,23], | |
[15,18,11]] | |
C = np.array([[1,1,2], | |
[1,2,2], | |
[1,4,3]]) | |
def crypt(x,y): | |
global T | |
Y = C | |
X = M | |
T = [[0,0,0], | |
[0,0,0], | |
[0,0,0]] | |
for i in range(len(X)): | |
for j in range(len(Y[0])): | |
for k in range(len(Y)): | |
T[i][j] += X[i][k] * Y[k][j] | |
def decrypt(x,y): | |
global C,M | |
I = inv(C) | |
C = I | |
M = T | |
crypt(M,C) | |
for i in T: | |
for j in i: | |
j=j+10 | |
for x, y in zip(range(1, 96), string.printable): | |
if j==x: | |
print (x,y) | |
crypt(M,C) | |
decrypt(M,C) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment