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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
| from Crypto.Util.number import * import hashlib from itertools import combinations from tqdm import *
class Per: def __init__(self, data): if type(data) is int: self.size = data self._list = [i+1 for i in range(self.size)] self._initialize() elif type(data) is list: self._list = data self.size = len(self._list)
def __mul__(self, other): return Per(self._iterList(self.getList(),other.getList()))
def __repr__(self): return str(self._list)
def __len__(self): return len(self._list)
def __pow__(self, other): tempList = self._list for _ in range(1,other): tempList = self._iterList(tempList, tempList) return Per(tempList)
def __str__(self): return str(self._list)
def getList(self): return self._list
def _initialize(self): for i in range(10): random.shuffle(self._list)
def _iterList(self, List1,List2): new_list = [] for elem in List1: new_list.append(List2[elem - 1]) return new_list
if(0): P2 = [82, 237, 32, 83, 30, 200, 116, 114, 4, 147, 171, 152, 193, 19, 170, 136, 186, 8, 124, 159, 225, 6, 180, 125, 74, 14, 255, 60, 187, 132, 222, 121, 56, 79, 57, 229, 87, 27, 72, 197, 201, 191, 75, 38, 135, 177, 165, 149, 17, 172, 173, 59, 210, 108, 31, 142, 163, 227, 178, 226, 73, 256, 190, 12, 103, 238, 129, 157, 219, 131, 67, 28, 68, 236, 168, 209, 245, 93, 61, 122, 208, 137, 49, 94, 111, 18, 161, 106, 54, 175, 70, 16, 110, 5, 218, 81, 233, 45, 91, 188, 151, 104, 148, 184, 228, 248, 150, 176, 167, 35, 130, 242, 126, 156, 42, 169, 232, 102, 50, 214, 179, 205, 9, 235, 97, 84, 246, 36, 76, 240, 52, 144, 98, 86, 99, 21, 64, 217, 15, 202, 206, 55, 244, 65, 23, 53, 250, 78, 22, 215, 25, 66, 143, 107, 195, 80, 196, 254, 174, 33, 162, 252, 141, 153, 43, 185, 211, 220, 115, 127, 216, 251, 139, 95, 146, 48, 239, 241, 37, 199, 13, 160, 90, 223, 123, 181, 120, 164, 118, 112, 128, 192, 249, 39, 2, 207, 71, 182, 145, 62, 3, 92, 183, 194, 100, 24, 133, 10, 117, 234, 29, 11, 140, 166, 85, 224, 230, 134, 189, 63, 46, 58, 231, 247, 47, 154, 44, 77, 89, 101, 69, 40, 26, 243, 253, 41, 51, 105, 155, 138, 1, 212, 20, 203, 213, 198, 158, 88, 109, 34, 119, 221, 113, 96, 204, 7]
for i in range(len(P2)): P2[i] -= 1
lenlist = [] count = 0 for i in range(len(P2)): len = 1 t = 0 loc = P2[i] chain = [loc] while(1): t = P2[loc] loc = t chain.append(loc) len += 1 if(t == i): if(len == 2): print(chain) break
chain64 = [[81, 136, 63, 11, 151, 65, 237, 104, 227, 76, 244, 212, 139, 201, 91, 15, 135, 20, 224, 46, 164, 42, 74, 167, 219, 62, 189, 111, 241, 211, 10, 170, 215, 223, 246, 157, 253, 95, 80, 207, 9, 146, 249, 33, 78, 60, 72, 67, 156, 195, 206, 132, 97, 44, 134, 98, 90, 69, 130, 51, 58, 177, 240, 0],[236, 50, 172, 138, 14, 169, 126, 245, 197, 181, 159, 32, 55, 141, 54, 30, 221, 57, 226, 43, 37, 26, 254, 203, 193, 38, 71, 27, 59, 225, 153, 106, 149, 214, 84, 110, 129, 239, 137, 216, 229, 100, 150, 24, 73, 235, 40, 200, 2, 31, 120, 178, 36, 86, 160, 161, 251, 220, 45, 176, 238, 154, 194, 1]] chain29 = [[29, 131, 143, 64, 102, 147, 77, 92, 109, 34, 56, 162, 140, 205, 23, 124, 96, 232, 25, 13, 18, 123, 234, 252, 112, 125, 83, 93, 4],[113, 155, 79, 121, 204, 99, 187, 163, 152, 142, 243, 202, 182, 89, 174, 145, 52, 209, 233, 242, 19, 158, 173, 94, 217, 133, 85, 17, 7]] chain20 = [[6, 115, 168, 114, 41, 190, 127, 35, 228, 88, 53, 107, 175, 47, 148, 21, 5, 199, 61, 255],[108, 166, 210, 28, 186, 119, 213, 165, 184, 122, 8, 3, 82, 48, 16, 185, 180, 12, 192, 248]] chain9 = [[68, 218, 188, 117, 101, 103, 183, 222, 230],[39, 196, 70, 66, 128, 75, 208, 116, 231]] chain4 = [[179, 198, 144, 22],[171, 250, 118, 49]] chain3 = [[105, 247, 87]]
locdic = {} locdic[191] = 191
chain3r = [0 for i in range(3)] for i in range(3): chain3r[2*i%3] = chain3[0][i] for i in range(3): locdic[chain3r[i]] = chain3r[(i+1)%3]
for i in range(4): locdic1 = locdic chain4r = [0 for j in range(8)] for j in range(8): if(j % 2 == 0): chain4r[j] = chain4[0][j//2] else: chain4r[j] = chain4[1][(j//2 + i) % 4] for i in range(8): locdic1[chain4r[i]] = chain4r[(i+1)%8]
for i in range(9): locdic2 = locdic1 chain18r = [0 for j in range(118)] for j in range(18): if(j % 2 == 0): chain18r[j] = chain9[0][j//2] else: chain18r[j] = chain9[1][(j//2 + i) % 9] for i in range(18): locdic2[chain18r[i]] = chain18r[(i+1)%18]
for i in trange(20): locdic3 = locdic2 chain40r = [0 for j in range(40)] for j in range(40): if(j % 2 == 0): chain40r[j] = chain20[0][j//2] else: chain40r[j] = chain20[1][(j//2 + i) % 20] for i in range(40): locdic3[chain40r[i]] = chain40r[(i+1)%40]
for i in range(29): locdic4 = locdic3 chain58r = [0 for j in range(58)] for j in range(58): if(j % 2 == 0): chain58r[j] = chain29[0][j//2] else: chain58r[j] = chain29[1][(j//2 + i) % 29] for i in range(58): locdic4[chain58r[i]] = chain58r[(i+1)%58]
for i in range(64): locdic5 = locdic4 chain128r = [0 for j in range(128)] for j in range(128): if(j % 2 == 0): chain128r[j] = chain64[0][j//2] else: chain128r[j] = chain64[1][(j//2 + i) % 64] for i in range(128): locdic5[chain128r[i]] = chain128r[(i+1)%128] P = [locdic5[j] for j in range(256)] tt = [0 for k in range(256)] for op in range(256): tt[op] = P[P[op]] if(tt != P2): print("Bad!") P = [locdic5[j]+1 for j in range(256)] check = hashlib.sha512(str(P).encode()).hexdigest() if(check == "91881f508f08fbafec1a6879fc3a1f215135c94c78f03fae8534d54dc05bd4a122a4e4508d32b9e02be08fbbb42a9e3335fc433c20e2da2e012d11b7324f6952"): print(P) exit()
mask = Per([87, 245, 52, 116, 114, 166, 4, 5, 7, 154, 38, 221, 36, 20, 16, 170, 42, 94, 159, 19, 246, 214, 251, 146, 135, 243, 216, 81, 48, 156, 190, 59, 75, 215, 244, 193, 1, 171, 254, 118, 70, 186, 33, 11, 25, 66, 182, 187, 115, 145, 140, 32, 97, 167, 63, 168, 203, 242, 121, 208, 111, 123, 31, 252, 205, 177, 184, 240, 117, 201, 104, 96, 130, 99, 56, 231, 2, 164, 85, 144, 60, 161, 169, 18, 61, 84, 82, 248, 109, 206, 41, 15, 153, 8, 253, 28, 210, 151, 236, 148, 98, 71, 100, 67, 155, 88, 250, 211, 54, 143, 73, 58, 134, 30, 17, 83, 219, 197, 199, 22, 178, 65, 256, 174, 53, 86, 21, 13, 223, 68, 3, 80, 101, 126, 74, 127, 162, 196, 92, 173, 90, 220, 35, 122, 172, 125, 107, 188, 120, 34, 45, 46, 110, 147, 228, 132, 138, 39, 124, 43, 137, 64, 183, 93, 160, 200, 108, 142, 49, 136, 27, 23, 202, 235, 24, 29, 238, 179, 241, 119, 128, 165, 141, 129, 62, 191, 149, 78, 40, 222, 181, 192, 229, 158, 77, 217, 102, 47, 50, 185, 131, 139, 163, 247, 103, 175, 230, 226, 69, 233, 176, 44, 51, 6, 79, 255, 207, 113, 232, 55, 152, 112, 76, 204, 198, 10, 212, 195, 249, 133, 209, 189, 234, 26, 95, 91, 213, 239, 105, 157, 37, 227, 14, 57, 237, 225, 194, 106, 89, 150, 180, 12, 218, 72, 224, 9]) mul = Per([114, 189, 92, 56, 252, 161, 202, 250, 131, 9, 111, 226, 223, 24, 14, 6, 99, 208, 195, 216, 141, 116, 167, 34, 5, 129, 15, 158, 178, 197, 4, 187, 27, 200, 144, 76, 74, 154, 86, 249, 93, 112, 46, 104, 25, 248, 40, 225, 38, 98, 186, 169, 64, 118, 33, 88, 26, 106, 183, 43, 201, 198, 242, 135, 110, 218, 244, 120, 83, 212, 192, 185, 148, 142, 11, 45, 232, 107, 18, 170, 60, 130, 247, 67, 65, 211, 182, 213, 134, 254, 70, 191, 210, 176, 145, 217, 82, 229, 125, 193, 155, 41, 113, 103, 49, 231, 133, 75, 109, 238, 126, 245, 163, 233, 227, 181, 51, 12, 143, 234, 239, 59, 240, 209, 42, 205, 230, 253, 203, 219, 23, 136, 32, 87, 102, 94, 85, 62, 172, 236, 124, 100, 256, 196, 50, 101, 206, 150, 89, 29, 61, 69, 246, 237, 16, 37, 184, 90, 162, 22, 36, 10, 31, 52, 190, 17, 55, 115, 251, 77, 214, 122, 1, 255, 151, 157, 241, 224, 3, 44, 48, 175, 194, 138, 179, 159, 160, 53, 80, 73, 8, 35, 156, 117, 58, 140, 221, 180, 72, 123, 147, 95, 228, 97, 71, 204, 39, 149, 2, 19, 173, 139, 146, 54, 96, 220, 79, 66, 57, 127, 243, 188, 165, 47, 235, 119, 7, 199, 30, 177, 63, 78, 105, 207, 153, 28, 132, 168, 84, 166, 171, 108, 21, 215, 164, 174, 121, 128, 91, 68, 20, 222, 81, 137, 13, 152]) temp = hashlib.sha512(str(mask * mul).encode()).hexdigest()
q,h = (18172777775303192159727657832771688633216215598877965158949208820296023901084764760222881725262986702478735713462424007788959106272018399708244805316198640706589775789778454299532286932532522325791791312289833643271330941006206604894333175027113622330874626579800679513666624938603337561309816936129926352661091319564303604867093095700819543458178063985869752612663625872468653351930763784372987474747809415652595112648835928004343413910248386752899307068129610089712815257479121368111201632430687614657790581254030567845143865728745079851692195657361359959987504557281840928862881924309178036648485188421874327022341, 392638098592460228418508462226385074690422702429214284385732305774317959159895775092251586043956914155602546821559652111400517952111932579557319610857122515237088379905875982863782386657213421074126519458271560586678974481499715849371311979995450766948182818105567819897007307737370051632369390705725712223883589110699340619034611462216676501782567065261228166297471411589579035544131060706331012337024260046692910523900152236991203944000276133732456285962825434272960749340504092014446362862600803570698206213069473248298100863523331832957430305801141935737006263947843411592717969844892834332104365594346376118846) c=4605640253217003331334964510174592254013178259349707648547335080743845433538772185582533054930473399495034133342299169373655297635370654237814250924077096784419954824350471683280656146814012837777204413608581553756866045890045788846665715321962704221105416079118007959490372975054302058194463432668018727266982561600329852084442818715440190956213811944269576719501924787366260795121132011879061730892865163591549129768412164655406373350666250339077746317309673325358941772202710386313434421388779073207650619564862431076222163014501544922959835509589742031678624743915535537547452120771609556012990490607104696154771 L = Matrix(ZZ, [[1, h], [0, q]]) f, g = L.LLL()[0] f,g = abs(f),abs(g) m = (f*c) % q % g * inverse(f, g) % g
flag = long_to_bytes(m ^^ int(temp,16)) print(flag)
|