printf("flag{"); int v3 = 10; int v5 = 10; char key[] = "adsfkndcls"; //上面的处理脚本求出的key char text[] = "killshadow"; //上面的处理脚本求出的text for (int i = 0; i < strlen(key); ++i) { for (int chr = 'A'; chr <= 'Z'; ++chr) { if ((chr - 39 - key[v3 % v5] + 97) % 26 + 97 == text[i]) { v3++; putchar(chr); break; } } } printf("}"); return0; }
RSA的判断
见[SUCTF2019]SignIn
根据第20行的求幂并取模,和65537这个数,直接看出是RSA加密,调用python相关库进行求解
同时结果转换成十六进制数,使用binascii.unhexlify()方法将其转换为字符串
WP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# 解密脚本 import gmpy2 import binascii
# 已知公私钥 n = 103461035900816914121390101299049044413950405173712170434161686539878160984549 p = 282164587459512124844245113950593348271 q = 366669102002966856876605669837014229419 e = 65537 c = 0xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35 # c = input('请输入密文') n = p * q phi_n = (p - 1) * (q - 1) # 对n取欧拉函数,p,q均为素数 d = gmpy2.invert(e, phi_n) # 即e*d mod phi_n = 1 (求逆元) m = gmpy2.powmod(c, d, n) # 即m = c^d mod n (求大整数c的d次幂模n取余) flag = str(hex(m))[2:] print(binascii.unhexlify(flag).decode())
数学基础考察
求模逆运算
例题:NSSCTF-[SWPUCTF 2021 新生赛]fakebase
题目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
flag = 'xxxxxxxxxxxxxxxxxxx'
s_box = 'qwertyuiopasdfghjkzxcvb123456#$' tmp = '' for i in flag: tmp += str(bin(ord(i)))[2:].zfill(8) b1 = int(tmp,2) s = '' while b1//31 != 0: s += s_box[b1%31] b1 = b1//31