RSA 解密的入门题型

在此复盘前几日做的几道 Crypto

where_is_my_flag

Download txt

p = 0xbdb8699374e4def5d3f3463e772ee20c08e1315c58bc3a762bd7df0eaa2df1411f60b76af536d98dea06f9baf1ba8e4e0e6e9e82f77128301b9402c1c3f8295f11e4334579f5c4c1349a7e1f979600ea203c1ecce035af549d29a42f3088504c09b3074e8680c2ef7b1a1076ac5f247faf539e8999bd21b89d5ab0010dd582db
q = 0x99c730753f5aa2a326e24c71b784351365a3f121b014879bbb218b70d6c295c549fff979a486693950b67895d8fee4bb3f3037f3c1998db33f80c4eda9a30573aa37eeb7987b7dc8ce6142b9f763006a6e70dc6e58a3848bfe127c987562aaf126ff6c9619f98242fe25018c94d35290131d77ef41be72231dbd394455ca8427
e = 0x10001
c = 0x690b7f4160011cd6ece55fd1fbf90e29c20c0c9d9528235ad986eba900cc5c30db3cb17fb99ecf0bf2a365cd3ae0e1e100e40d584ed0ff960ef8f489c8698da70718f72c96ec71acb388d232af1da54995f681ffe05440788569368a48970edfe2ef3b27dedb2c0ee2cac7d0820f58a9a26a4a33a7a1f09a1f3898589ff74ff14e4ba9e126e94fb8dbf2f8b26146924858dada87f490822226d498a55c92864eca2d0e50111d8dbff0544c5d3cffc2341737abe3897b12d1834b2a0ab3c94d1cb2e9300cdc9559a5fae7d1a5f33cd08605eb2476d775cf9faadb032de0b057d08e0b686d022e880917c844fdd19b22881a946540ca90bfc235dafb98f15e8899

编写一段 python 脚本跑一下

import gmpy2
p = 0xbdb8699374e4def5d3f3463e772ee20c08e1315c58bc3a762bd7df0eaa2df1411f60b76af536d98dea06f9baf1ba8e4e0e6e9e82f77128301b9402c1c3f8295f11e4334579f5c4c1349a7e1f979600ea203c1ecce035af549d29a42f3088504c09b3074e8680c2ef7b1a1076ac5f247faf539e8999bd21b89d5ab0010dd582db
q = 0x99c730753f5aa2a326e24c71b784351365a3f121b014879bbb218b70d6c295c549fff979a486693950b67895d8fee4bb3f3037f3c1998db33f80c4eda9a30573aa37eeb7987b7dc8ce6142b9f763006a6e70dc6e58a3848bfe127c987562aaf126ff6c9619f98242fe25018c94d35290131d77ef41be72231dbd394455ca8427
e = 0x10001
c = 0x690b7f4160011cd6ece55fd1fbf90e29c20c0c9d9528235ad986eba900cc5c30db3cb17fb99ecf0bf2a365cd3ae0e1e100e40d584ed0ff960ef8f489c8698da70718f72c96ec71acb388d232af1da54995f681ffe05440788569368a48970edfe2ef3b27dedb2c0ee2cac7d0820f58a9a26a4a33a7a1f09a1f3898589ff74ff14e4ba9e126e94fb8dbf2f8b26146924858dada87f490822226d498a55c92864eca2d0e50111d8dbff0544c5d3cffc2341737abe3897b12d1834b2a0ab3c94d1cb2e9300cdc9559a5fae7d1a5f33cd08605eb2476d775cf9faadb032de0b057d08e0b686d022e880917c844fdd19b22881a946540ca90bfc235dafb98f15e8899
n = p * q
d=gmpy2.invert(e,(p-1)*(q-1))
m=gmpy2.powmod(c,d,n)
import binascii
print(binascii.unhexlify(hex(m)[2:]))

微信图片_20210831205621.png

RSA-Equation

p+q= 0x15554bf3279b5a5ff3a6f51348840a5c77f85d649ef89fe6f6aecca3b7a4f8954d94c041b9bf9c53605e69bf381df6b1e264dbe7cf3760d816bca53bc783efd62
p-q= 0x277f7e82a74a5d8142ffc15b6a580535a1b64d6e4e200918902ca748abaeebaaa08b56883c6d76ebb3a53e4461cb51629b7297af887a72cdcf57f7dc77896968
e=0x10001
c= 0x545040e44624d0b2ef5dd3e389d7e3edcd0933791f7ccce390d7c8637dd7d26d5d14ecada079d839d71f6326259e9fb65e89c8a52419ed2ffee953c78f5d66335c4cadbc2c48034430a7d3ce4c468eb17c4f04cddfe271928b794048a4a59478c4261c44e7c3e8f9fd946d48620c0069a9327cb22a4c0502d1e9869991c4b922
import gmpy2
from Crypto.Util.number import long_to_bytes
from z3 import *
tmp1=0x15554bf3279b5a5ff3a6f51348840a5c77f85d649ef89fe6f6aecca3b7a4f8954d94c041b9bf9c53605e69bf381df6b1e264dbe7cf3760d816bca53bc783efd62
tmp2=0x277f7e82a74a5d8142ffc15b6a580535a1b64d6e4e200918902ca748abaeebaaa08b56883c6d76ebb3a53e4461cb51629b7297af887a72cdcf57f7dc77896968
e=0x10001
c=0x545040e44624d0b2ef5dd3e389d7e3edcd0933791f7ccce390d7c8637dd7d26d5d14ecada079d839d71f6326259e9fb65e89c8a52419ed2ffee953c78f5d66335c4cadbc2c48034430a7d3ce4c468eb17c4f04cddfe271928b794048a4a59478c4261c44e7c3e8f9fd946d48620c0069a9327cb22a4c0502d1e9869991c4b922
s = Solver()
p,q = Ints('p q')
s.add(p+q == tmp1)
s.add(p-q == tmp2)
assert s.check() == sat
p = s.model()[p].as_long()
q = s.model()[q].as_long()
n = q*p
phi = (p-1)*(q-1)
d = gmpy2.invert(e,phi)
m = gmpy2.powmod(c,d,n)
print(long_to_bytes(m))

微信截图_20210901090446.png

RSA-Equation2

n=16917955357177705838022522227269189799965442955600174230088241413537748036079610427667748524760416412487661588166675433898394627618977795412467578931925290358440662780942041112815203687805808800979128075090221137838151372846654787093946656482304031633775358207228010135390832522575861986102844835573116079075374771222923318301544600822685589433165393483870570768619713138725020836976344994143665005213595439734053715247430701190483139697651308683944225607919788529538100719847326451607419315958484481451634531624954226369336218518430937719669057217473641902380243356961565889376657557909528540953750939711249576195159
e=65537
p+q=267250288454671020661183002864902079825043927948084290018881840749593744112726102797024780930797632709553108642750613400441660075135953435838879572761149456222440690951092454409936578252836007774319573115773705552877746875261145722418936676843582728011234303760521211480177882717639401447544081327143079896120
c=5556174183094477266451814135598079847549101214607407493539824119455757033446976990042962516935280719453306508436587735802442820646417947364018203517042867867234303222841927154859105937645608430659139623801595899283410063126536085399147208144097197880122970573526524116735044315018453029904516767525608508679020577616271754886842387942346107665596391743557339734244348287686755256712318046694093530306203491446373883714768977770886274094556846171675194528687326913219088784425334478253460076116644849541623671796578618297488203818462587973285321935678023132310392911491050341349681920275418686930590504234068089136064
import gmpy2
from Crypto.Util.number import long_to_bytes
from z3 import *
tmp1=267250288454671020661183002864902079825043927948084290018881840749593744112726102797024780930797632709553108642750613400441660075135953435838879572761149456222440690951092454409936578252836007774319573115773705552877746875261145722418936676843582728011234303760521211480177882717639401447544081327143079896120
tmp2=16917955357177705838022522227269189799965442955600174230088241413537748036079610427667748524760416412487661588166675433898394627618977795412467578931925290358440662780942041112815203687805808800979128075090221137838151372846654787093946656482304031633775358207228010135390832522575861986102844835573116079075374771222923318301544600822685589433165393483870570768619713138725020836976344994143665005213595439734053715247430701190483139697651308683944225607919788529538100719847326451607419315958484481451634531624954226369336218518430937719669057217473641902380243356961565889376657557909528540953750939711249576195159
e=65537
c=5556174183094477266451814135598079847549101214607407493539824119455757033446976990042962516935280719453306508436587735802442820646417947364018203517042867867234303222841927154859105937645608430659139623801595899283410063126536085399147208144097197880122970573526524116735044315018453029904516767525608508679020577616271754886842387942346107665596391743557339734244348287686755256712318046694093530306203491446373883714768977770886274094556846171675194528687326913219088784425334478253460076116644849541623671796578618297488203818462587973285321935678023132310392911491050341349681920275418686930590504234068089136064
s = Solver()
p,q = Ints('p q')
s.add(p+q == tmp1)
s.add(p*q == tmp2)
assert s.check() == sat
p = s.model()[p].as_long()
q = s.model()[q].as_long()
n = q*p
phi = (p-1)*(q-1)
d = gmpy2.invert(e,phi)
m = gmpy2.powmod(c,d,n)
print(long_to_bytes(m))

微信截图_20210901090524.png

更新于

请我喝[茶]~( ̄▽ ̄)~*

1sme 微信支付

微信支付