1.Baby Rsa
p+q : 0x1232fecb92adead91613e7d9ae5e36fe6bb765317d6ed38ad890b4073539a6231a6620584cea5730b5af83a3e80cf30141282c97be4400e33307573af6b25e2ea
(p+1)(q+1) : 0x5248becef1d925d45705a7302700d6a0ffe5877fddf9451a9c1181c4d82365806085fd86fbaab08b6fc66a967b2566d743c626547203b34ea3fdb1bc06dd3bb765fd8b919e3bd2cb15bc175c9498f9d9a0e216c2dde64d81255fa4c05a1ee619fc1fc505285a239e7bc655ec6605d9693078b800ee80931a7a0c84f33c851740
e : 0xe6b1bee47bd63f615c7d0a43c529d219
d : 0x2dde7fbaed477f6d62838d55b0d0964868cf6efb2c282a5f13e6008ce7317a24cb57aec49ef0d738919f47cdcd9677cd52ac2293ec5938aa198f962678b5cd0da344453f521a69b2ac03647cdd8339f4e38cec452d54e60698833d67f9315c02ddaa4c79ebaa902c605d7bda32ce970541b2d9a17d62b52df813b2fb0c5ab1a5
enc_flag : 0x50ae00623211ba6089ddfae21e204ab616f6c9d294e913550af3d66e85d0c0693ed53ed55c46d8cca1d7c2ad44839030df26b70f22a8567171a759b76fe5f07b3c5a6ec89117ed0a36c0950956b9cde880c575737f779143f921d745ac3bb0e379c05d9a3cc6bf0bea8aa91e4d5e752c7eb46b2e023edbc07d24a7c460a34a9a
已知n = p * q , phin = (p - 1) * (q - 1),根据上式得到n = (p + 1) * (q + 1) - ( p + q ) - 1, phin = (p + 1) * (q + 1) - 2 *( p + q )
enc_flag(encoded flag 密文)也就是c
直接代公式就好
'''Baby Rsa'''
# a = p + q
# b = (p + 1) * (q + 1)
a = 0x1232fecb92adead91613e7d9ae5e36fe6bb765317d6ed38ad890b4073539a6231a6620584cea5730b5af83a3e80cf30141282c97be4400e33307573af6b25e2ea
b = 0x5248becef1d925d45705a7302700d6a0ffe5877fddf9451a9c1181c4d82365806085fd86fbaab08b6fc66a967b2566d743c626547203b34ea3fdb1bc06dd3bb765fd8b919e3bd2cb15bc175c9498f9d9a0e216c2dde64d81255fa4c05a1ee619fc1fc505285a239e7bc655ec6605d9693078b800ee80931a7a0c84f33c851740
e = 0xe6b1bee47bd63f615c7d0a43c529d219
d = 0x2dde7fbaed477f6d62838d55b0d0964868cf6efb2c282a5f13e6008ce7317a24cb57aec49ef0d738919f47cdcd9677cd52ac2293ec5938aa198f962678b5cd0da344453f521a69b2ac03647cdd8339f4e38cec452d54e60698833d67f9315c02ddaa4c79ebaa902c605d7bda32ce970541b2d9a17d62b52df813b2fb0c5ab1a5
enc_flag = 0x50ae00623211ba6089ddfae21e204ab616f6c9d294e913550af3d66e85d0c0693ed53ed55c46d8cca1d7c2ad44839030df26b70f22a8567171a759b76fe5f07b3c5a6ec89117ed0a36c0950956b9cde880c575737f779143f921d745ac3bb0e379c05d9a3cc6bf0bea8aa91e4d5e752c7eb46b2e023edbc07d24a7c460a34a9a
n = b - a - 1
phin = b - 2 * a
m = pow(enc_flag, d, n)
print(long_to_bytes(m))
2.rsa 2
题目给了一个py文件,里面给了n和e以及 flag = "flag{" + hashlib.md5(hex(d)).hexdigest() + "}"
(1) 用网页分解n得到p,q
(2) 涉及到了一个新的模块 hashlib,不过这里涉及到的不深,所以只是去简单了解了一下涉及到的函数的用法,简单说就是hashlib.md5()内需要传进一个bytes类型字符串,hexdigest()函数显示其十六进制等效项,encode()函数将字符串转换为字节,encode() 方法以指定的编码格式编码字符串,默认编码为 ‘utf-8’
参考:Python encode方法:XX.encode(‘utf-8‘)究竟是什么?_程序米虫的博客-CSDN博客_.encode('utf-8')
(3) hex(d).encode()输出一个bytes类型字符串(其中hex()将十进制转为十六进制并以字符串形式表示)
b'0x13b8f87d588e2aa4a27296cf2898f56ab4c8deb5a1222ec080e23afecaf7f975'
这里直接放进md5()会得到一个错误结果,上网搜一下发现这个是在python2上运行的结果,在python3上需要在字符串末尾加一个L
b'0x13b8f87d588e2aa4a27296cf2898f56ab4c8deb5a1222ec080e23afecaf7f975L'
参考: