NKCTF2024
NKCTF2024——Crypto——部分题解
Ez_Math
task.py
1 | from Crypto.Util.number import * |
分解n
$$
\because x \equiv (q+r)^p \mod n
$$
则
$$
x \equiv r^p \mod q
$$
同理
$$
y \equiv (pq + r)^p \mod n
$$
则
$$
y \equiv r^p \mod q
$$
$$
\therefore x - y \equiv 0 \mod q
$$
又因为
$$
x \equiv q+r \mod p
$$
$$
y \equiv r \mod p
$$
gcd(x-y-q,n) = kp
求解时候发现这个kp
是1024bit,猜测这个kp
实际上是$p\times q$,除掉$q$即可
求得$p,q$之后可以求$r,s$
求M1
$$
\because z \equiv (s + 1)^{m_1} \mod s^3
$$
则
$$
z \equiv 1^{m_1} + m_1s + \frac{m_1(m_1-1)}{2}s^2 \mod s^3
$$
模掉$s^2$得
$$
z \equiv 1 + m_1s \mod s^2
$$
这样就很容易求解$m_1$了
求解M2
$m_2$应该不大,直接在模p下求解
发现$e\times (s-1)$和$p-1$不互素,公因数为4
那么先求解出$(m_2) ^ 4 \mod p$
然后有限域开根
exp
1 | from Crypto.Util.number import* |
GGH
task.sage
1 | from sage.all import * |
$$
\because c = mW + r
$$
很容易知道
$$
m = (c-r)\times W^{-1}
$$
其中$W$是$260\times 260$的矩阵,$m,r,c$是$1\times 260$的向量
通过$W$的规模可以知道$n = 260$
给了$delta < 20$,尝试爆破出r然后解密
exp
1 | c = (14697, -103356, 74779, 95622, -11650, 524678, -258697, 388940, -399559, -437273, 267702, -978292, 686059, 835272, 809650, 759647, -573204, 989361, -696040, -694133, -831908, -477981, 724090, -1228907, -120150, -774399, -591584, -1291399, 254792, -134668, -109064, 198801, -749156, -816935, -1015728, -899139, 957539, 797980, 622496, 636293, 1795867, 688081, 1327891, 94650, -1563715, 789969, -2006496, 1400404, -1134347, -736944, 148919, -665150, -1081234, -973028, 881767, 3307694, -1584719, -805716, 1360628, -896122, -862741, -1014915, 848040, 8791, 1010424, -627001, -1915331, 1734060, -578582, -1250807, 1002361, -2555983, 382933, 876467, -517111, -890007, 1120942, 328836, 1070931, 3060471, 1282311, 900451, -1368524, 2383556, -100407, 1472198, -636598, 1481797, 1250775, 279604, -880140, 940241, 474972, 854830, -4072298, 440151, -622028, 2260879, -2738469, 974549, 103401, -2590853, -12923, -1612830, 1275543, -693632, -2681181, 536356, -199335, -638932, -3363587, 3897884, 1328506, -1114079, -553394, -2175335, -56629, 1842637, 48649, 1561646, 1874518, 514713, -1927387, -20432, -915037, -840193, 870019, 4671103, 1119753, 837031, 420138, 2875929, 1527979, 363294, -1591329, -2499404, -1504185, -161931, -1799591, 245185, 2222818, -3921583, -1357181, 453979, 1872321, -297401, 2490480, 2786635, -2838351, -737681, -2545091, -1696116, 425623, 147974, -1739229, -3945245, 1255070, -1820074, -2190869, -1254018, 2211542, 3565405, -1063183, 1179506, 1707422, 3324989, -105580, 4502495, 332793, -1505723, -493912, 756291, 2609637, -396470, 3318630, 1424448, -871428, -2341694, -1474359, 78429, 4140695, -1223022, 1726067, -1830797, 2252423, 634142, -1162911, 657946, 1161669, 314917, 637551, 128154, 1944407, 467548, -2980735, -1097568, -2143663, -251256, 2520771, -1815714, -1814059, 305958, -2599700, 1076361, -2794868, 2798862, -3126794, 2466492, 2951889, 2541846, -2737433, 2364461, 519766, 522438, -728868, -1180942, 1205432, 2089627, -844456, -427481, 1117668, 1503704, 4061528, -889185, 1678865, 4025442, 871542, -3081410, 2014316, 667040, -3925491, 1776813, 1304258, 2248592, 2204897, 1250071, 883217, -1259669, -2071139, -3292080, -1706324, 626620, 1202724, -361433, 1343175, 1486927, -2365569, 4589072, -2439656, -1727340, 2108002, -1245002, -1392031, -2058070, -814170, -116156, -878803, -1503880, 3505220, -891921) |