p = 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483 q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407 e = 65537 c = 83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034 t = (p-1)*(q-1) n = p*q
# returns d such that e * d == 1 modulo t, or 0 if no such y exists. d = gmpy2.invert(e,t)
# Decryption m = pow(c,d,n) print"Solved ! m = %d" % m
打开手机9宫格输入法,两个一组,例如21=a,22=b 33 53 21 41 43 74 74 43 61 71 53 32 f l a g i s s i m p l e
RSAROLL
逆推解法
先分解n920139713得到18443,49891
1 2 3 4 5 6 7 8 9 10 11
import gmpy2
p,q,N,e = 18443,49891,920139713,19 d = gmpy2.invert(e,(p-1)*(q-1)) flag = [] with open("RSAROll.txt") as f: f.readline() f.readline() for i in f: flag.append(chr(pow(int(i),d,N))) print("".join(flag))
爆破解法
1 2 3 4 5 6 7 8 9
n,e,dic,flag = 920139713,19,{},'' for i in range(33,128): dic[str(i**e%n)] = chr(i) with open("RSAROLL.txt") as f: f.readline() f.readline() for i in f: flag += dic[i.replace('\n','')] print(flag)
79 67 85 123 67 70 84 69 76 88 79 85 89 68 69 67 84 78 71 65 72 79 72 82 78 70 73 69 78 77 125 73 79 84 65 ASCII得到:O C U { C F T E L X O U Y D E C T N G A H O H R N F I E N M } I O T A 根据第二点,注意格式CTF{ } OCU{CFTELXOUYDECTNGAHOHRNFIENM}IOTA CTF{ }
O C U { C F T E L X O U Y D E C T N G A H O H R N F I E N M } I O T A
提示Fair-Play,应该是普莱菲尔密码,密钥在给出的句子中。 参考:playfair密码 The quick brown fox jumps over the lazy dog! 去掉重复字母,ij视为同一个,组成5x5矩阵
1 2 3 4 5 6 7 8
t h e q u i/j c k b r o w n f x m p s v l a z y d g 按照加密方法逆向解密,同列这里向左移,不同列矩阵替换得到flag ih xo {sm zd od ci km od ci sm zd} cf fx {pl ay fa ir is fa ir pl ay}
培根密码: A aaaaa B aaaab C aaaba D aaabb E aabaa F aabab G aabba H aabbb I abaaa J abaab K ababa L ababb M abbaa N abbab O abbba P abbbb Q baaaa R baaab S baaba T baabb U babaa V babab W babba X babbb Y bbaaa Z bbaab
DCCDC CCDDD CDCCC DDCCC CCCCC CDDCD CCCCD CCCCC/CDCCC DCCDC/CCCDC CDDDC CDDDC CDCDD baaba aabbb abaaa bbaaa aaaaa abbab aaaab aaaaa/abaaa baaba/aaaba abbba abbba ababb s h i y a n b a i s c o o l
defPanDuan(): for i in range(len(e)): a = e[i] for j in range(i+1,len(e)): b = e[j] # print(i,j) a = a.replace('L','') b = b.replace('L','') if gmpy2.gcd(int(a,16),int(b,16)) == 1: return a,b
f = open('problem.txt') txt = f.read().splitlines() f.close() # print(txt) List = {} e = [] for i in range(1,len(txt)): a = re.findall('729743L : (.*) : 0x',txt[i]) b = re.findall('%s : (.*)L}'%a[0],txt[i]) e.append(a[0]) List[a[0]]=b[0]
a = PanDuan() print('e1=%d'%int(a[0],16)) print('e2=%d'%int(a[1],16)) print('message1=%d'%int(List[a[0]],16)) print('message2=%d'%int(List[a[1]],16))
e1=1804229351 e2=17249876309 message1=78552378607874335972488545767374401332953345586323262531477516680347117293352843468592985447836452620945707838830990843415342047337735534418287912723395148814463617627398248738969202758950481027762126608368555442533803610260859075919831387641824493902538796161102236794716963153162784732179636344267189394853 message2=98790462909782651815146615208104450165337326951856608832305081731255876886710141821823912122797166057063387122774480296375186739026132806230834774921466445172852604926204802577270611302881214045975455878277660638731607530487289267225666045742782663867519468766276566912954519691795540730313772338991769270201 n = '0xa5f7f8aaa82921f70aad9ece4eb77b62112f51ac2be75910b3137a28d22d7ef3be3d734dabb9d853221f1a17b1afb956a50236a7e858569cdfec3edf350e1f88ad13c1efdd1e98b151ce2a207e5d8b6ab31c2b66e6114b1d5384c5fa0aad92cc079965d4127339847477877d0a057335e2a761562d2d56f1bebb21374b729743' n = int(n,16)
# s & t gcd, s, t = gmpy2.gcdext(e1, e2) if s < 0: s = -s message1 = gmpy2.invert(message1, n) if t < 0: t = -t message2 = gmpy2.invert(message2, n) plain = gmpy2.powmod(message1, s, n) * gmpy2.powmod(message2, t, n) % n print(plain)
# 10进制转16进制再转ASCII flag = str(binascii.a2b_hex(hex(plain)[2:]),encoding='utf-8') print(flag)
from base64 import b64decode from hashlib import md5 from itertools import product
List = product(['Y','y'],['M','m'],['F','f'],['Z','z'],['Z','z'],['T','t'],['Y','y'],['0'],['D','d'],['3'],['R','r'],['M','m'],['D','d'],['3'],['R','r'],['M','m'],['M','m'],['T','t'],['I','i'],['Z','z']) for i in List: Str = ''.join(i) # print(Str) Md5 = md5(b64decode(Str)).hexdigest() #计算哈希 if Md5 == '16478a151bdd41335dcd69b270f6b985': #对比 print('flag:' + str(b64decode(Str),encoding='utf-8'))
pub = RSA.importKey(open('public.pem').read()) n = long(pub.n) e = long(pub.e) print n print e # n = 74207624142945242263057035287110983967646020057307828709587969646701361764263 # e = 65537
defFAN(n, m): i = 0 z = [] s = 0 while n > 0: if n % 2 != 0: z.append(2 - (n % 4)) else: z.append(0) n = (n - z[i])/2 i = i + 1 z = z[::-1] l = len(z) for i in range(0, l): s += z[i] * m ** (l - 1 - i) return s
deFAN = {} for i in range(100): a = FAN(i,3) deFAN[a]=i # print deFAN r = '2712733801194381163880124319146586498182192151917719248224681364019142438188097307292437016388011943193619457377217328473027324319178428' b = 0 str1 = '' while b < len(r): if int(r[b:b + 4]) in deFAN: str1 += '%d' % (deFAN[int(r[b:b + 4])]) b += 4 elif int(r[b:b + 3]) in deFAN: str1 += '%02d' % (deFAN[int(r[b:b + 3])]) b += 3 elif int(r[b:b + 2]) in deFAN: str1 += '%02d' % (deFAN[int(r[b:b + 2])]) b += 2 elif int(r[b:b + 1]) in deFAN: str1 += '%02d' % (deFAN[int(r[b:b + 1])]) b += 1
n = 0x367198D6B5614E95813ADD8F22A4717BC72BE1EABD933D1B86944FDB75B8ED230BE62D7D1B69D222095C128C86F82012ECB116191FD9D018A6D02F84DB27BC51A21307DC86F4BF771C691C143E5ABE549B5BD2D6EB1A21FD6270E7E1B48FE0611FBB2E1B0B3524E6F4DE8B4E4A345DA44A13DE825B72608DB6C7C4A40B78266E6C87BBFDEF6B48381D49C4507A58BCD47B76D64B45908B158BD7EBC4DACB0B1CFD6C2C19574F40EB2EFD0E9E10DC7005CAD39BCAF52B9EAC3873368D69031C5E724684A44F068EFD1D3DC096D9B5D6411E58BDEE43E46B99A0D0494B9DB28195AF901AFF130D4A6E203DAD08DA57FA7E40262A5BADB2A323EDA28B44696AB305D d = 4221909016509078129201801236879446760697885220928506696150646938237440992746683409881141451831939190609743447676525325543963362353923989076199470515758399 c = 0x1e04304936215de8e21965cfca9c245b1a8f38339875d36779c0f123c475bc24d5eef50e7d9ff5830e80c62e8083ec55f27456c80b0ab26546b9aeb8af30e82b650690a2ed7ea407dcd094ab9c9d3d25a93b2140dcebae1814610302896e67f3ae37d108cd029fae6362ea7ac1168974c1a747ec9173799e1107e7a56d783660418ebdf6898d7037cea25867093216c2c702ef3eef71f694a6063f5f0f1179c8a2afe9898ae8dec5bb393cdffa3a52a297cd96d1ea602309ecf47cd009829b44ed3100cf6194510c53c25ca7435f60ce5f4f614cdd2c63756093b848a70aade002d6bc8f316c9e5503f32d39a56193d1d92b697b48f5aa43417631846824b5e86
m = hex(pow(c, d, n)).rstrip("L") # print(m) print(str(unhexlify(m[2:]),encoding='utf-8'))