# 第三届河北省大学生网络与信息安全选拔赛-Crypto-WP

### math [一血]

from Crypto.Util.number import *
from hashlib import md5

flag = "XXX"
assert len(flag) == 14

hack = 0

for char in flag:
hack*= ord(char)

print hack
#hack = 64364485357060434848865708402537097493512746702748009007197338675
#flag_to_submit = "flag{" + flag + "}"


hack = pad * last_char * (1 + ...+n)


#python2

from Crypto.Util.number import *
from hashlib import md5
from itertools import combinations

len_flag = 14
hack = 64364485357060434848865708402537097493512746702748009007197338675

raw_input()

def get_all_candidate(hack):
return [chr(i) for i in range(32, 129) if hack % i == 0]

def backtrack(i, h, p, ans, deep):
if h < 0:
return False
if len(ans) > len_flag:
return False
if h / ord(i) == p and p == bytes_to_long(md5(ans[::-1]).digest()):
print ans[::-1]
raw_input()
return True
candidate = get_all_candidate(h/ord(i) - p)

if not candidate:
return False
else:
done = False
for j in candidate:
if not backtrack(j, h/ord(i) - p, p, ans + j, deep + 1):
pass
else:
done = True

return done

c = [3, 3, 5, 5, 7, 107, 487, 607, 28429, 29287, 420577267963, 3680317203978923, 1002528655290265069]
for r in range(1, 14):
for factors in combinations(c, r):
for f in factors:
continue
print factors

for k in get_all_candidate(hack):
print "————————"
# raw_input()

#flag{d0y0ul1keM@TH?}


### rsa [一血]

n=22561172536677648559787604959523195072179259409010314452272275495363968755657659138742248552894595529382230922241140656549843203305826473571445603834757787255736898096406153231539420740606617993518122317969410178044748567867122389763000873035273736666346624950112390179154333942974763371969584888993523474785703126407758739432302547292610981495520537518042779911203114321445895667363586256353373620877601821136901641493999842631467944779970213905636039444786194077923883593166806502276718151627041975659783265190382918098071120315433981040541826821825277381380527761087122467964932153713194745798177997722042776467823
e=65537
c=19328196358751658895450655392637127310222166740765135237100788629359244004186017531913542633846914446577530070361990508415396536818488820222120779983101438854297373364445564149526771854808100054824945213757075977600155153794380392843250249421227703382007213012131876851828154156292326203220320138218001022549062888054700986604924812634110284449199586085012678155983265546720208230278018003075240556412400816319188195980878492235194635353445804239756712398169138480766013684092405117638265070954612493845540746705265223696626365851780172702852574231465793269945857869635628236488314786408909172723290733282538209968247
2d+phi(n)=24114829899810646031152927156356440623523513950820570971172657869605295042116148846058663431685177495769257006671204194892172258274371716987566720411992577862665150660975369465525447840121901649254226473481778722127378865051369383216827923429416969207860136204997233907126159519798979336641129811969668501246242088955574999107571615543760265312436830459903515683689045577164832265662220035876790112563967655077079968881948607640842264058086427875121914327767238217629898601698947580820398969991591620306905238666381003642185305206988597488619954300386153696163111726576675781435154124871145727025050765235161063120482


2 × d 2 \times d + + p h i ( n ) phi(n) = = A A
A × e A \times e = = 2 × d × e 2\times d\times e + + e × p h i ( n ) e\times phi(n) m o d p h i ( n ) mod phi(n)
A × e A\times e = = 2 m o d p h i ( n ) 2mod phi(n)
p h i ( n ) phi(n) = = A × e − 2 A \times e - 2

from Crypto.Util.number import *
from gmpy2 import *
from libnum import *

n = 22561172536677648559787604959523195072179259409010314452272275495363968755657659138742248552894595529382230922241140656549843203305826473571445603834757787255736898096406153231539420740606617993518122317969410178044748567867122389763000873035273736666346624950112390179154333942974763371969584888993523474785703126407758739432302547292610981495520537518042779911203114321445895667363586256353373620877601821136901641493999842631467944779970213905636039444786194077923883593166806502276718151627041975659783265190382918098071120315433981040541826821825277381380527761087122467964932153713194745798177997722042776467823
c = 19328196358751658895450655392637127310222166740765135237100788629359244004186017531913542633846914446577530070361990508415396536818488820222120779983101438854297373364445564149526771854808100054824945213757075977600155153794380392843250249421227703382007213012131876851828154156292326203220320138218001022549062888054700986604924812634110284449199586085012678155983265546720208230278018003075240556412400816319188195980878492235194635353445804239756712398169138480766013684092405117638265070954612493845540746705265223696626365851780172702852574231465793269945857869635628236488314786408909172723290733282538209968247

#2d+phi(n) = 24114829899810646031152927156356440623523513950820570971172657869605295042116148846058663431685177495769257006671204194892172258274371716987566720411992577862665150660975369465525447840121901649254226473481778722127378865051369383216827923429416969207860136204997233907126159519798979336641129811969668501246242088955574999107571615543760265312436830459903515683689045577164832265662220035876790112563967655077079968881948607640842264058086427875121914327767238217629898601698947580820398969991591620306905238666381003642185305206988597488619954300386153696163111726576675781435154124871145727025050765235161063120482
#a = 2d+phi(n)
#d = a//2
#print(d)

d = 12057414949905323015576463578178220311761756975410285485586328934802647521058074423029331715842588747884628503335602097446086129137185858493783360205996288931332575330487684732762723920060950824627113236740889361063689432525684691608413961714708484603930068102498616953563079759899489668320564905984834250623121044477787499553785807771880132656218415229951757841844522788582416132831110017938395056281983827538539984440974303820421132029043213937560957163883619108814949300849473790410199484995795810153452619333190501821092652603494298744309977150193076848081555863288337890717577062435572863512525382617580531560241

m = pow(c,d,n)
print(n2s(m))
#easyctf{ilnirawvhfpey2nrxx}


### crypto

import random
rand = random.randint(1, 10)
flag = 'flag{******************************}'
k = []
for i in range(len(flag)):
k.append(ord(flag[i]) & 15 ^ rand)
k.append(ord(flag[i]) & 240)

print k
#k = [4, 96, 14, 96, 3, 96, 5, 96, 9, 112, 4, 48, 7, 48, 3, 48, 0, 48, 0, 96, 6, 96, 6, 48, 1, 48, 6, 96, 11, 48, 1, 96, 3, 96, 3, 96, 4, 48, 7, 96, 2, 48, 0, 48, 1, 96, 11, 48, 11, 48, 2, 48, 0, 96, 2, 48, 3, 96, 10, 48, 0, 48, 4, 48, 7, 48, 0, 48, 6, 96, 1, 96, 3, 96, 15, 112]



rand = 2
flag = ''
k = [4, 96, 14, 96, 3, 96, 5, 96, 9, 112, 4, 48, 7, 48, 3, 48, 0, 48, 0, 96, 6, 96, 6, 48, 1, 48, 6, 96, 11, 48, 1, 96,
3, 96, 3, 96, 4, 48, 7, 96, 2, 48, 0, 48, 1, 96, 11, 48, 11, 48, 2, 48, 0, 96, 2, 48, 3, 96, 10, 48, 0, 48, 4, 48,
7, 48, 0, 48, 6, 96, 1, 96, 3, 96, 15, 112]
for i in range(0, len(k), 2):
for j in range(0,128):
if ((k[i] ^ rand) == (j & 15)) and (k[i+1] == (j & 240)):
flag += chr(j)

print(flag)
#flag{6512bd43d9caa6e02c990b0a82652dca}


04-22 2877
08-18 338
07-23 832
01-24 2万+
11-06 5985
01-07 8511
07-21 1万+
03-20 1万+
12-20 3万+
05-10 2803
05-06 563
01-09 1万+