# picproblem
# 题目
from PIL import Image | |
from Crypto.Util.number import * | |
from numpy import array, zeros, uint8 | |
import gmpy2 as gp | |
import cv2 | |
from key import x,y,kn,hint | |
image = cv2.imread("flag.jpg") | |
img_gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY) | |
imagearray = array(img_gray) | |
h = len(imagearray) | |
w = len(imagearray[0]) | |
assert 1301149798051259562945444365741194129602596348352064372203373*pow(x, 2) == 1175915431138623881271508290982969935822476052419526528443170552123*pow(y, 2) + 1301149798051259562945444365741194129602596348352064372203373 | |
x1 = round(x/y*0.001, 16) | |
u1 = y*3650/x | |
x2 = round(x/y*0.00101, 16) | |
u2 = y*3675/x | |
x3 = round(x/y*0.00102, 16) | |
u3 = y*3680/x | |
kt = [x1, x2, x3] | |
temp_image = zeros(shape=[h, w, 3], dtype=uint8) | |
print(len(temp_image)) | |
print(len(temp_image[0])) | |
print(len(temp_image[0][1])) | |
for k in range(0, kn): | |
for i in range(0, h): | |
for j in range(0, w): | |
x1 = u1 * x1 * (1 - x1) | |
x2 = u2 * x2 * (1 - x2) | |
x3 = u3 * x3 * (1 - x3) | |
r1 = int(x1*255) | |
r2 = int(x2*255) | |
r3 = int(x3*255) | |
for t in range(0, 3): | |
temp_image[i][j][t] = (((r1+r2) ^ r3)+imagearray[i][j][t]) % 256 | |
x1 = kt[0] | |
x2 = kt[1] | |
x3 = kt[2] | |
encflagarray = Image.fromarray(temp_image) | |
encflagarray.show() | |
encflagarray.save("encflag.jpg") | |
#************************************hint************************************** | |
m = hint | |
p = getPrime(512) | |
q = getPrime(512) | |
n = p * q | |
e = 65537 | |
phi = (p-1)*(q-1) | |
dp = gp.invert(e, p-1) | |
c = pow(m, e, n) | |
#n = 85413323752199019806030766630760449394238054889872415531186815348349883843039718091361611175963675771467536496812507338620957273406076058263122453235926619595761737396698699834116678598534261542535530241537247151318756003375573850725841254167462648747492270335084402716816450008370008491069875351593380154253 | |
#dp = 1576424214336939000475035870826282526256046059505538052583882122452307602095912733650442447289122473348318614749578285418144935611098423641334952097553125 | |
#c = 53653254613997095145108444611576166902006080900281661447007750088487109015427510365774527924664116641019490904245926171500894236952984157500461367769566121581870986304353174732328118576440353500038670030097108081972287049673200783198844842527470746431369314585103203118824985764754487936404004696485346196488 |
先看 hint
dp 泄露
kn=8
然后我们只要知道 x,y 就能求解。比赛的时候完全没意识到这个是佩尔方程(主要还是遇到的不够多)
只化出了这个
from gmpy2 import * | |
def Cal_CF(List): | |
List.reverse() | |
fenmu = 0 | |
fenzi = 1 | |
for i in List: | |
fenmu, fenzi = fenzi, i * fenzi + fenmu | |
return fenmu, fenzi | |
t = 903751 | |
m = isqrt(t) | |
x = t ** (0.5) | |
a = [] | |
a.append(m) | |
b = m | |
c = 1 | |
while a[-1] != 2 * a[0]: | |
c = (t - b * b) // c | |
tmp = (x + b) / c | |
a.append(int(tmp)) | |
b = a[-1] * c - b | |
print(len(a) - 1) | |
print(a) | |
a = a[:-1] | |
fenmu, fenzi = Cal_CF(a) | |
print(fenmu) | |
print(fenzi) |
得到 x,y
求解
from PIL import Image | |
from Crypto.Util.number import * | |
from numpy import array, zeros, uint8 | |
import gmpy2 as gp | |
import cv2 | |
imagearray = cv2.imread(r"C:\Users\gx\Downloads\picproblemd865943d\encflag.jpg") | |
h = len(imagearray) | |
w = len(imagearray[0]) | |
y=1604145232044543633656616254647708451166351104281510395737885491696385806407267633308545985473789119651681711082023113933085624628557168423578747544761597312012713558891523798820667618256495398479378172124019360339427592449217208805888502769358288779859969965560832505104388955091637704481336716722418336373334467787371085728212260231330510705797124224353810509272250940285165605853594811893804251478850270703294638335268305881655491870226553141286503109543313414279220480589704210363277523457948607498351377843904335637032510420141505975997452077477296326035048463179997347136990808017374750824810458605412236391952910679246288287664717533857743462935708681309073915761377477454479206054016260422865457862565353002789887917196437750618212918420129464330488021272187952177063175896447842395209693304502304253471733746765257510395226972224876277717457205220726240042035259947453816668460757995771018155703600926745905595162857982860955545877343914746294034180707 | |
x=1524993807674193841904821512553946379967374698278296055158206699585083472817489721493862711615915407326315660670541801753616900039772802728925226091475860689682871555641241500183892397513037971186709123629077584204226084524811673794984687840178772052545441242927492902583547355565525538664836516589721942980577095421561886873928634330640979800040574060218872787212426630202508118484269553983399179155489583316400107655564222453437462724749097265122300644936717434151331633092585140183510349369422527440264746843972834927860065578557836150798690530172694679514231722613822246810010130005324032492360889531553803832398604563088256410481865243771216990603166993198935358471831328395618477974126824762560872337594997394218234427050399655270848385995088586420526886397320949350980406936200217112040971433660322179072288438842964957568719036794320203116263329623589339367497303140938070334557345834226085189140858264388063745189833584962825509843279678826240558480527560 | |
x1 = round(x/y*0.001, 16) | |
u1 = y*3650/x | |
x2 = round(x/y*0.00101, 16) | |
u2 = y*3675/x | |
x3 = round(x/y*0.00102, 16) | |
u3 = y*3680/x | |
kt = [x1, x2, x3] | |
temp_image = zeros(shape=[h, w, 3], dtype=uint8) | |
print(len(temp_image)) | |
print(len(temp_image[0])) | |
print(len(temp_image[0][1])) | |
for k in range(0, 8): | |
for i in range(0, h): | |
for j in range(0, w): | |
x1 = u1 * x1 * (1 - x1) | |
x2 = u2 * x2 * (1 - x2) | |
x3 = u3 * x3 * (1 - x3) | |
r1 = int(x1*255) | |
r2 = int(x2*255) | |
r3 = int(x3*255) | |
for t in range(0, 3): | |
temp_image[i][j][t] = (imagearray[i][j][t]-((r1+r2) ^ r3)) % 256 | |
x1 = kt[0] | |
x2 = kt[1] | |
x3 = kt[2] | |
encflagarray = Image.fromarray(temp_image) | |
encflagarray.show() |
太菜了 wo