from libnum import * from Crypto.Util.number import *
c = [] n = 390643660915400759356028673149168279560687093035302974183909784119138903637101610150171466601442693220550718178154721365461636077209566533154335718201358899342358662848545345180263124134588375803369006010468316238614932369094974862842683683363587543473163915923045398254122306762084945489324575516415794686273949909352344088141474136179402651003388916093283318052977257982248730053350207666237541564674407802737159850168950514444047006592253696165165211262564161
m = "" for i in c: if jacobi(int(i),n) == 1: m += '0' else: m += '1' print(long_to_bytes(int(m[::-1],2))) # paluctf{1_4m_th3_b0td_1n_t3st_1n_th3_r0w}
江枫渔火对愁眠
task.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
from Crypto.Util.number import * flag = b'paluctf{******************}' p = getPrime(512) q = getPrime(512) m = bytes_to_long(flag) n = p * q e = 0x10001 c = pow(m, e, n) leak1 = p & q leak2 = p | q print(n) print(leak1) print(leak2) print(c) # 116117067844956812459549519789301338092862193317140117457423221066709482979351921356314593636327834899992321545232613626111009441254302384449742843180876494341637589103640217194070886174972452908589438599697165869525189266606983974250478298162924187424655566019487631330678770727392051485223152309309085945253 # 8605081049583982438298440507920076587069196185463800658188799677857096281403951362058424551032224336538547998962815392172493849395335237855201439663804417 # 13407373154151815187508645556332614349998109820361387104317659096666170318961881115942116046384020162789239054091769561534320831478500568385569270082820389 # 77391898018025866504652357285886871686506090492775075964856060726697268476460193878086905273672532025686191143120456958000415501059102146339274402932542049355257662649758904431953601814453558068056853653214769669690930883469679763807974430229116956128100328073573783801082618261383412539474900566590518020658
python from Crypto.Util.number import getStrongPrime, GCD, bytes_to_long import os from flag import flag
deflong_to_bytes(long_int, block_size=None): """Convert a long integer to bytes, optionally right-justified to a given block size.""" bytes_data = long_int.to_bytes((long_int.bit_length() + 7) // 8, 'big') return bytes_data ifnot block_size else bytes_data.rjust(block_size, b'\x00')
defgen_keys(bits=512, e=5331): """Generate RSA modulus n and public exponent e such that GCD((p-1)*(q-1), e) == 1.""" whileTrue: p, q = getStrongPrime(bits), getStrongPrime(bits) n = p * q if GCD((p-1) * (q-1), e) == 1: return n, e
defpad(m, n): """Pad the message m for RSA encryption under modulus n using PKCS#1 type 1.""" mb, nb = long_to_bytes(m), long_to_bytes(n) assertlen(mb) <= len(nb) - 11 padding = os.urandom(len(nb) - len(mb) - 3).replace(b'\x01', b'') return bytes_to_long(b'\x00\x01' + padding + b'\x00' + mb)
defencrypt(m, e, n): """Encrypt message m with RSA public key (e, n).""" returnpow(m, e, n)
n, e = gen_keys() m = pad(bytes_to_long(flag), n) c1, c2 = encrypt(m, e, n), encrypt(m // 2, e, n)
print(f"n = {n}\ne = {e}\nc1 = {c1}\nc2 = {c2}")
# n = 128134155200900363557361770121648236747559663738591418041443861545561451885335858854359771414605640612993903005548718875328893717909535447866152704351924465716196738696788273375424835753379386427253243854791810104120869379525507986270383750499650286106684249027984675067236382543612917882024145261815608895379 # e = 5331 # c1 = 60668946079423190709851484247433853783238381043211713258950336572392573192737047470465310272448083514859509629066647300714425946282732774440406261265802652068183263460022257056016974572472905555413226634497579807277440653563498768557112618320828785438180460624890479311538368514262550081582173264168580537990 # c2 = 43064371535146610786202813736674368618250034274768737857627872777051745883780468417199551751374395264039179171708712686651485125338422911633961121202567788447108712022481564453759980969777219700870458940189456782517037780321026907310930696608923940135664565796997158295530735831680955376342697203313901005151
p = 151832619619952089992267716058068444251307600220706203871589765844990819175654042917774490787590849720202969240992246624166668570786235406779778934647681250166384828094778797880304323848041273713831052602978130708287523575488166230706021974231380611512371425017998262828486267505916086636495016213117818476079 q = 136011049679334940861511595857042329781653809853866436171389745534855895446196665892885140663304371230055953209984856118200410958041858815679721863717912611066674050454954534686280510303474769670492647228370259394337403855556056590338482704020086450814990436480639792318856245688841995452742464887239898730723 n = p*q d = gmpy2.invert(e,phi) m = pow(c,d,n) print(bytes.fromhex(hex(int(m))[2:])) # paluctf{51b98a17-6843-4e3b-b06c-3cd956bc944c}