1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| >>> from cryptonita.mod import inv_matrix >>> enc = "bbcbp_zqrafjq}ehowmdw{jifop_y_wo_hqoaoetavcicwdadgoafkatlkuf" >>> table = "{}abcdefghijklmnopqrstuvwxyz_" >>> p = "securinets{" >>> m = len(table) >>> enc_index = [table.index(i) for i in enc] >>> p_index = [table.index(i) for i in p] >>> enc_index [3, 3, 4, 3, 17, 28, 27, 18, 19, 2, 7, 11, 18, 1, 6, 9, 16, 24, 14, 5, 24, 0, 11, 10, 7, 16, 17, 28, 26, 28, 24, 16, 28, 9, 18, 16, 2, 16, 6, 21, 2, 23, 4, 10, 4, 24, 5, 2, 5, 8, 16, 2, 7, 12, 2, 21, 13, 12, 22, 7] >>> p_index [20, 6, 4, 22, 19, 10, 15, 6, 21, 20, 0] >>> import numpy as np >>> P = np.array([20, 6, 4, 22]).reshape(2, 2).T >>> P array([[20, 4], [ 6, 22]]) >>> C = np.array([3, 3, 4, 3]).reshape(2, 2).T >>> C array([[3, 4], [3, 3]]) >>> iC = inv_matrix(C, m) >>> iC array([[28, 11], [ 1, 28]], dtype=int32) >>> iK = np.dot(P, iC) >>> iK = np.dot(P, iC)%m >>> iK array([[13, 13], [16, 15]], dtype=int32) >>> C1 = np.array([17, 28, 27, 18]).reshape(2, 2).T >>> P1 = np.dot(iK, C1)%m >>> P1 array([[ 5, 5], [25, 6]], dtype=int32) >>> P0 = np.dot(iK, C)%m >>> P0 array([[20, 4], [ 6, 22]], dtype=int32) >>> P = np.array(enc_index[:9]).reshape(3, 3).T >>> P array([[ 3, 3, 27], [ 3, 17, 18], [ 4, 28, 19]]) >>> C = np.array(p_index[:9]).reshape(3, 3).T >>> C array([[20, 22, 15], [ 6, 19, 6], [ 4, 10, 21]]) >>> iC = inv_matrix(C, m) >>> iC array([[ 5, 9, 27], [18, 3, 7], [25, 1, 4]], dtype=int32) >>> iK = np.dot(P, iC)%m >>> iK array([[19, 5, 7], [17, 9, 11], [13, 23, 3]], dtype=int32) >>> P0 = np.dot(iK, C)%m >>> P0 array([[ 3, 3, 27], [ 3, 17, 18], [ 4, 28, 19]], dtype=int32) >>> P array([[ 3, 3, 27], [ 3, 17, 18], [ 4, 28, 19]]) >>> C1 = np.array(enc_index[9:18]).reshape(3, 3).T >>> C1 array([[ 2, 18, 9], [ 7, 1, 16], [11, 6, 24]]) >>> P1 = np.dot(iK, C1)%m >>> P1 array([[ 5, 12, 13], [15, 4, 10], [17, 14, 6]], dtype=int32) >>> len(p_index) 11 >>> P = np.array(p_index[:9]).reshape(3, 3).T >>> C = np.array(enc_index[:9]).reshape(3, 3).T >>> iC = inv_matrix(C, m) >>> iK = np.dot(P, iC)%m >>> iK array([[26, 14, 4], [12, 17, 16], [ 8, 12, 15]], dtype=int32) >>> P0 = np.dot(iK, C)%m >>> P array([[20, 22, 15], [ 6, 19, 6], [ 4, 10, 21]]) >>> P0 array([[20, 22, 15], [ 6, 19, 6], [ 4, 10, 21]], dtype=int32) >>> p_index [20, 6, 4, 22, 19, 10, 15, 6, 21, 20, 0] >>> C1 = np.array(enc_index[9:18]).reshape(3, 3).T >>> P1 = np.dot(iK, C1)%m >>> P1 array([[20, 13, 3], [ 0, 10, 10], [ 4, 14, 15]], dtype=int32) >>> iK = np.array([[26, 14, 4], [12, 17, 16], [8, 12, 15]])
|