if hashlib.sha256((XXXX + random_str[4:].encode())).hexdigest() != str_sha256: returnFalse
returnTrue
defgetPQN(self): whileTrue: p = getStrongPrime(2048) q = getStrongPrime(2048) n = p * q if p.bit_length() == 2048and q.bit_length() == 2048and n.bit_length() == 4096: return p, q, n
defencrypt(self): p, q, n = self.getPQN() m = bytes_to_long(flag) e = 0x10001 c = pow(m, e, n) p = bin(p)[2:] p1 = list(p[:1024]) p2 = list(p[1024:]) p1[random.choice([i for i, c inenumerate(p1) if c == '1'])] = '0' p2[random.choice([i for i, c inenumerate(p1) if c == '0'])] = '1' return n, ''.join(p1) + ''.join(p2), c
defhandle(self): ifnot self.proof(): self.request.sendall(b'Error Hash!') return n, p, c = self.encrypt() self.request.sendall('Press 1 to get ciphertext\n'.encode()) number = self.request.recv(512).strip().decode() if number == '1': self.request.sendall((str(n) + '\n').encode()) self.request.sendall((str(p) + '\n').encode()) self.request.sendall((str(c) + '\n').encode()) else: self.request.sendall('Incorrect input!\n'.encode()) return
from Crypto.Util.number import * import gmpy2 from tqdm import *
n = 603929041261800903893255846837373435975689488156082111538579411971234122241475748036901372456410420191268918203740933624479627880138860787078343962957545877493495346831028915623609911739520855865598159115403599691845611787894864022849387193442196306247844978619825889396851220746270712372629345235420222076680115154790661980407543403831934888441296510749707016149742835334975569330963811702631399381154725473397239011407333239568323785920549918563058163802790187563167758518996273164519358725587751057556099683209931508156206102023550113078755175573231054144175740037978473444981801474458374782704295305402882601070280107624282520071733642472567932754610400320318631599250987727798785732693028629127928075161764000633755172649305820758541646921112640799416373141028867694424520169726284794592230472739528017824591893518858631575238481300188255385565135530781399021638113121796002810581237621059229401475373166398218013467690838657741784353265467188916419980824688886467277205321029087429010136873982224751707535560753990915173665180626848355707628545030678081326994468311753531184000767912265077615115921131730201921373353972239662406236256449307913217499123008959838210605102941439012579314919044679872148810171587616630982300997769 P = "11010001001011001110010111110000100100111111011100110000001011110010001010111010001000110011110011100101101111000010000110010011010001100111010001101101010110110000001000111101001111001111100111010001110001110000011101110111100010100110111111010101101000100101011101111100100100011101001001010101010100100100010111001101101001001101010111101001101010111111111010101111000110010011001001010010101110010110111110111001011011000111101110100100001100100111101100010100100000111001111111111000101001101111111001010000111110000110111110110101101001111010010001111111010011101111111011101000011101100010000000101000010010001100101001001100000000110111110101001101001010110111011100101001111111111110010100101101001110000000100011000001011110110101110111010001101000000101111101011010010000000110100011110101000000110011100001001010000111110101111011001110001000101010010110100010010000011010000000010110010110110010100000010111100011000101001110100100001110011010101011010111101000100010001000100100001110001100000011001000000011010110000100011000010010011100101101000001011110011010111111011001001101000101010011001010100000101011011010001101000110100001010111000111011111000111000110010111011111001001000111101101111101101100110000010001010100000000010111001011010110101000110010010100000110010001010001010111110010001110100100001110110100011100110010101101010010000110010000000000001101001001111000001001110111100101011010000101000001101100000011010110110001001100001010110010111110000100010010001111000111110111001110111010000010110111101110010011101010001101000100011111100111101110100100001001010110000110011110011000110010000111111110011100001110011010010010001011000011101000001100100110101001010110101000100010110000111001100011101000110010101101110000001110101010010100011111000011011010110001111000001000111011110111000111111011011101101011011011010101010001001000001001101111101101011010000001111001101010000100100011011010011011011011110011101001110011000101101010001000111100101010111001110100001001011101000111110110111111101001100110111011" c = 86686439679874830246557653015232666024548117379353423678475364097072178826632356840355752060131181776717167764598857424931346233132869924918276685776350661070390576961130941951957979601769745016239304945501929062576701514720613007436301407348380329606694430576562909174904437860869521166636000289719433717305895080524202468368216882473127238573270504191177749274378107593390170231953722023523109786520395037511557586384515517033167064188185912051635528465308305202059386081496894767608262032863369259646855260874931901314784267182224186084544278686060811418808427473393401031779270067234650782676467179083936163361798893672177127354928129838729299397848748974202105320442165321749085841967661828478087899131573349766763269557239693467725757622240790567302886026262903788677893782986023554124746338684896334712802104286022426080359219997110717128626202867661389035295735029082783484639744693093659639224377233571685420055087016612362091684619532730540899821020173872616220719344374207934384262583860759996308412468708264575433904901696415884548016664119511545715549106666120050640487895135909555493016879887730329494392167451911914419832673885582817232756022767909864103483310200762274943174788555599167912909253375001595679099288103 e = 65537
a1 = [i for i, c inenumerate(list(P[:1024])) if c == '0'] a2 = [i for i, c inenumerate(list(P[1024:])) if c == '1']
# p2不变的情况 for i in tqdm(a1): pp = list(P[:1024]) pp[int(i)] = "1" p = int(("".join(pp) + "".join(list(P[1024:]))),2) if isPrime(p): print(f"p = {p}") q = n // p d = gmpy2.invert(e,(p-1)*(q-1)) m = pow(c,d,n) flag = long_to_bytes(m) ifb"D0g3{"in flag: print(flag) break # D0g3{sYuWzkFk12A1gcWxG9pymFcjJL7CqN4Cq8PAIACObJ}
defasserts(pt: bytes): num = pt[-1] iflen(pt) == 16: result = pt[::-1] count = 0 for i in result: if i == num: count += 1 else: break if count == num: returnTrue else: returnFalse else: returnFalse
defdecrypt(c): iv = c[:32] cipher = c[32:] plain_text = cbc_decrypt(binascii.unhexlify(cipher), binascii.unhexlify(iv)) if asserts(plain_text): returnTrue else: returnFalse
if hashlib.sha256((XXXX + random_str[4:].encode())).hexdigest() != str_sha256: returnFalse
returnTrue
defhandle(self): ifnot self.proof(): self.request.sendall(b'Error Hash!') return cipher = encrypt() self.request.sendall('Welcome to AES System, please choose the following options:\n1. encrypt the flag\n2. decrypt the flag\n'.encode()) n = 0 while n < 65536: options = self.request.recv(512).strip().decode() if options == '1': self.request.sendall(('This is your flag: %s\n' % cipher).encode()) elif options == '2': self.request.sendall('Please enter ciphertext:\n'.encode()) recv_cipher = self.request.recv(512).strip().decode() if decrypt(recv_cipher): self.request.sendall('True\n'.encode()) else: self.request.sendall('False\n'.encode()) else: self.request.sendall('Input wrong! Please re-enter\n'.encode()) n += 1 return
print("未知数:",Xnum) print(tail) print(hash) print("开始爆破") for i in product(table,repeat=Xnum): head = ''.join(i) t = hashlib.sha256((head + tail).encode()).hexdigest() if t == hash: print('爆破成功!结果是:', end='') print(head) p.send(head.encode()) break
defdec(iv, token): p.sendline(b"2") p.sendlineafter(b"Please enter ciphertext:", binascii.hexlify(iv+token)) p.recvline() returnb'True'in p.recvline()
counter = len(token) // 16 true_flag = '' t = token[::] for ct inrange(1, counter): oldIv = t[16*ct-16:16*ct] token = t[16*ct:16*ct+16] flag = [] # 记录原始解密值 suf = []
for i in tqdm(range(1,17)): for j inrange(256): payload = b"D0g3{U_Get_Fl4g}"[:16-i] + bytes([j]) + bytes(suf) + token if dec(payload[:16], payload[16:]): flag.append(j ^ i)
suf.insert(0, j) for v inrange(len(suf)): suf[v] = suf[v] ^ i ^ (i+1) print(flag) break
ans = ""
flag.reverse()
for i inrange(16): ans += chr(oldIv[i] ^ flag[i]) true_flag += ans print(true_flag)
# -*- coding:utf-8 -*- import os import random import string import hashlib import socketserver from secret import * import uuid import gmpy2 from Crypto.Util.number import isPrime, long_to_bytes, getStrongPrime, bytes_to_long
defget_flag(head): table = string.printable name = ''.join([random.choice(table) for i inrange(10)]) return head + '{' + str(uuid.uuid5(uuid.NAMESPACE_OID, name)) + '}'
defrelation(): a, b = 0, 0 for i inrange(x - (2**2 - 1)): a += pow(e1, i) for j inrange(3): b += pow(e2, j) if a == b: returnTrue returnFalse
defget_pqr(): whileTrue: p = getStrongPrime(1024) q = getStrongPrime(1024) if p % 4 == 3and q % 4 == 3: break r = 2 whileTrue: r = r * x if r.bit_length() > 1024and isPrime(r - 1): r = r - 1 break return p, q, r
defencrypt(): if relation(): print('success') else: print('false') flag = get_flag('D0g3')
a = (inv_p * p * mq + inv_q * q * mp) % n b = n - int(a) c = (inv_p * p * mq - inv_q * q * mp) % n d = n - int(c) aa = [a, b, c, d] for i in aa: flag = long_to_bytes(int(i)) ifb"D0g3"in flag: print(flag) break
decrypt1(c1,p,q,inv_p,inv_q,pq) # D0g3{82309bce-9db6-53 phi = (p-1)*(q-1)*(r-1) d = gmpy2.invert(e2,phi) m = pow(c2,d,n) print(long_to_bytes(m)) # 40-a9e4-a67a9ba15345} # D0g3{82309bce-9db6-5340-a9e4-a67a9ba15345}