p = random_prime(2**1024) q = random_prime(2**1024) a = randint(0, 2**1024) b = randint(0, 2**1024) n = p * q e = 0x10001 flag = b'' m = pad(flag) assert m < n
c = pow(m, e, n)
print(f"c={c}") print(f"n={n}") print(f"h1={p + b * q}") print(f"h2={a * p + q}")
from Crypto.Util.number import * from gmpy2 import * a = random_prime() b = random_prime() g = random_prime() h = 2*g*a*b+a+b whilenot is_prime(h): a = random_prime() b = random_prime() g = random_prime() h = 2*g*a*b+a+b N = 2*h*g+1 e from part1's flag flag=b'' c=pow(bytes_to_long(flag),e,N) print(N) print(g) print(c) #N=10244621233521168199001177069337072125430662416754674144307553476569744623474797179990380824494968546110022341144527766891662229403969035901337876527595841503498459533492730326942662450786522178313517616168650624224723066308178042783540825899502172432884573844850572330970359712379107318586435848029783774998269247992706770665069866338710349292941829996807892349030660021792813986069535854445874069535737849684959397062724387110903918355074327499675776518032266136930264621047345474782910332154803497103199598761422179303240476950271702406633802957400888398042773978322395227920699611001956973796492459398737390290487 #g=2296316201623391483093360819129167852633963112610999269673854449302228853625418585609211427788830598219647604923279054340009043347798635222302374950707 #c=7522161394702437062976246147354737122573350166270857493289161875402286558096915490526439656281083416286224205494418845652940140144292045338308479237214749282932144020368779474518032067934302376430305635297260147830918089492765917640581392606559936829974748692299762475615766076425088306609448483657623795178727831373194757182797030376302086360751637238867384469269953187938304369668436238848537646544257504724753333177938997524154486602644412199535102323238852958634746165559537630341890450666170836721803871120344373143081664567068672230842855208267929484000179260292518351155693154372172449820053764896414799137097
print(long_to_bytes(int(pow(enc,inverse(e,(p-1)*(q-1)),N)))) #b'flag{I wish you success in your cryptography career}' #b'H&NCTF{I wish you success in your cryptography career}'
import matplotlib.pyplot as plt import cv2 import numpy as np from PIL import Image defarnold_encode(image, shuffle_times, a, b): """ Arnold shuffle for rgb image Args: image: input original rgb image shuffle_times: how many times to shuffle Returns: Arnold encode image """ arnold_image = np.zeros(shape=image.shape)
h, w = image.shape[0], image.shape[1] N = h for time inrange(shuffle_times): for ori_x inrange(h): for ori_y inrange(w): new_x = (1*ori_x + b*ori_y)% N new_y = (a*ori_x + (a*b+1)*ori_y) % N arnold_image[new_x, new_y, :] = image[ori_x, ori_y, :] image = np.copy(arnold_image) cv2.imwrite('en_flag.png', arnold_image, [int(cv2.IMWRITE_PNG_COMPRESSION), 0]) return arnold_image
n = n=604805773885048132038788501528078428693141138274580426531445179173412328238102786863592612653315029009606622583856638282837864213048342883583286440071990592001905867027978355755042060684149344414810835371740304319571184567860694439564098306766474576403800046937218588251809179787769286393579687694925268985445059
d1 = random[1] - random[0]
d2 = random[2] - random[1]
d3 = random[3] - random[2]
d4 = random[4] - random[3]
T1 = d2^2 - d3*d1
T2 = d3^2 - d4*d2
m = gcd(T1, T2)
print("m bits:", m.nbits())
print("is prime?", is_prime(m))
a = (random[2] - random[1]) * inverse_mod(random[1] - random[0], m) % m
n = 604805773885048132038788501528078428693141138274580426531445179173412328238102786863592612653315029009606622583856638282837864213048342883583286440071990592001905867027978355755042060684149344414810835371740304319571184567860694439564098306766474576403800046937218588251809179787769286393579687694925268985445059
# m = 5084057673176634704877325918195984684237263100965172410645544705367004138917087081637515846739933954602106965103289595670550636402101057955537123475521383
# c = 2989443482952171039348896269189568991072039347099986172010150242445491605115276953489889364577445582220903996856271544149424805812495293211539024953331399
还是一样的,我们要先解离散对数
1 2 3 4 5
n = 2^512 m = 3097502164103987164323080671192386511065857410221288153061140622970224914473224807053016180200525552838404973541878618391348653867355109392070344210878871 c = 7575520525465161327133831389027121519268752255113564686585808502942641702897542584106400374391419523883832010238676747853882832409855139906428435538853383 e = discrete_log(c, Mod(m, n)) print(e)
N = 155296910351777777627285876776027672037304214686081903889658107735147953235249881743173605221986234177656859035013052546413190754332500394269777193023877978003355429490308124928931570682439681040003000706677272854316717486111569389104048561440718904998206734429111757045421158512642953817797000794436498517023
hint = 128897771799394706729823046048701824275008016021807110909858536932196768365642942957519868584739269771824527061163774807292614556912712491005558619713483097387272219068456556103195796986984219731534200739471016634325466080225824620962675943991114643524066815621081841013085256358885072412548162291376467189508
c = 32491252910483344435013657252642812908631157928805388324401451221153787566144288668394161348411375877874802225033713208225889209706188963141818204000519335320453645771183991984871397145401449116355563131852618397832704991151874545202796217273448326885185155844071725702118012339804747838515195046843936285308
N = 133196604547992363575584257705624404667968600447626367604523982016247386106677898877957513177151872429736948168642977575860754686097638795690422242542292618145151312000412007125887631130667228632902437183933840195380816196093162319293698836053406176957297330716990340998802156803899579713165154526610395279999
hint = 88154421894117450591552142051149160480833170266148800195422578353703847455418496231944089437130332162458102290491849331143073163240148813116171275432632366729218612063176137204570648617681911344674042091585091104687596255488609263266272373788618920171331355912434290259151350333219719321509782517693267379786
from Crypto.Util.number import * import gmpy2 from hashlib import sha256 from gmssl.sm4 import CryptSM4, SM4_ENCRYPT, SM4_DECRYPT
N = 133196604547992363575584257705624404667968600447626367604523982016247386106677898877957513177151872429736948168642977575860754686097638795690422242542292618145151312000412007125887631130667228632902437183933840195380816196093162319293698836053406176957297330716990340998802156803899579713165154526610395279999 hint = 88154421894117450591552142051149160480833170266148800195422578353703847455418496231944089437130332162458102290491849331143073163240148813116171275432632366729218612063176137204570648617681911344674042091585091104687596255488609263266272373788618920171331355912434290259151350333219719321509782517693267379786 c = '476922b694c764725338cca99d99c7471ec448d6bf60de797eb7cc6e71253221035eb577075f9658ac7f1a40747778ac261787baad21ee567256872fa9400c37' c = bytes.fromhex(c)
r = 7166351305785506670352015492214713707534657162937963088592442157834795391917
from Crypto.Util.number import * from secret import flag from rsa.prime import getprime while(1): p=getprime(256) q=getprime(256) if isPrime(3*p**5+4*q**5): print(3*p**5+4*q**5) break
e = 65537 print(pow(bytes_to_long(flag), e, p * q)) #72063558451087451183203801132459543552092564094711815404066471440396765744526854383117910805713050240067432476705168314622044706081669935956972031037827580519320550326077291392722314265758802332280697884744792689996718961355845963752788234205565249205191648439412084543163083032775054018324646541875754706761793307667356964825613429368358849530455220484128264690354330356861777561511117 #2864901454060087890623075705953001126417241189889895476561381971868301515757296100356013797346138819690091860054965586977737630238293536281745826901578223
n = 72063558451087451183203801132459543552092564094711815404066471440396765744526854383117910805713050240067432476705168314622044706081669935956972031037827580519320550326077291392722314265758802332280697884744792689996718961355845963752788234205565249205191648439412084543163083032775054018324646541875754706761793307667356964825613429368358849530455220484128264690354330356861777561511117 ciphertext = 2864901454060087890623075705953001126417241189889895476561381971868301515757296100356013797346138819690091860054965586977737630238293536281745826901578223 e = 65537