当前位置:网站首页>Xctf attack and defense world crypto advanced area best_ rsa
Xctf attack and defense world crypto advanced area best_ rsa
2022-07-03 19:26:00 【l8947943】
1. Enter the environment , Download the attachment
Compressed package for topic , Include 4 File , Pictured :
given 2 Public key files and 2 Ciphertext file , With regular RSA Decryption methods: decrypt separately , Decryption failed (n by 2048 Bits are hard to decompose )
2. Problem analysis
- Continue to review RSA
- In plain text m, The secret is c, modulus n = p * q
- Use Euler functions ,φ(n) = (p - 1) * (q- 1)
- Select a large integer e, bring gcd(e, φ(n) ) = 1,e Used to encrypt the secret key
- Private key d It can be calculated from the value of Euler function , Satisfy ed mod φ(n) ≡ 1
- In plain text m Encrypted into ciphertext c:m^e ≡ c (mod n)
- Will ciphertext c Decrypt to plaintext m:c^d ≡ m (mod n)
- Common mode attack
Guess it should be the same plaintext , Used 2 Different public key encryption results in different ciphertexts , Using the same modulus and different public key indices for multiple encryption of the same plaintext may lead to common mode attacks .
Look at the boss's wp after :https://blog.csdn.net/weixin_44795952/article/details/108933406, Understand what common mode attack is
So called common mode , Is plaintext m identical , model n identical , Use two public keys e1,e2 Encrypt to get two private keys d1,d2 And two ciphertexts c1,c2
Common mode attack , When n Without change , know n,e1,e2,c1,c2 . Can be in the don't know d1,d2 Under the circumstances , figure out m.
There's a condition , namely
gcd(e1,e2)=1
- Attack principle
There are integers s 1 s_{1} s1, s 1 s_{1} s1( One is one minus one. ), Satisfy :
e 1 ∗ s 1 + e 2 ∗ s 2 = 1 e_{1} * s_{1} + e_{2} * s_{2} = 1 e1∗s1+e2∗s2=1
from Crypto.Util.number import long_to_bytes, bytes_to_long
from Crypto.PublicKey import RSA
from gmpy2 import gcd, invert
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x - (b // a) * y, y
with open('pic/publickey1.pem', 'rb') as f:
f1 = f.read()
pub1 = RSA.importKey(f1)
n = int(pub1.n)
e1 = int(pub1.e)
with open('pic/publickey2.pem', 'rb') as f:
f2 = f.read()
pub2 = RSA.importKey(f2)
e2 = int(pub2.e)
with open('pic/cipher1.txt', 'rb') as f:
c1 = f.read()
c1 = bytes_to_long(c1)
print(c1)
with open('pic/cipher2.txt', 'rb') as f:
c2 = f.read()
c2 = bytes_to_long(c2)
print(c2)
print(gcd(e1, e2))
s = egcd(e1, e2)
s1 = s[1]
s2 = s[2]
if s1 < 0:
s1 = -s1
c1 = invert(c1, n)
elif s2 < 0:
s2 = -s2
c2 = invert(c2, n)
m = pow(c1, s1, n) * pow(c2, s2, n) % n
print(m)
print(long_to_bytes(m).decode())
边栏推荐
- Chapitre 1: le roi de shehan a mal calculé
- Go home early today
- Use unique_ PTR forward declaration? [repetition] - forward declaration with unique_ ptr? [duplicate]
- Chapter 2: 4-digit Kaplan number, search even digit Kaplan number, search n-digit 2-segment sum square number, m-digit ingenious square number without 0, specify the number to form a 7-digit square nu
- I study database at station B (4): DQL
- 05 -- QT OpenGL draw cube uniform
- FBI warning: some people use AI to disguise themselves as others for remote interview
- QT -- qfileinfo file information reading
- Analyse du Code du planificateur ego bspline Section Optimizer (1)
- CMD implements the language conversion of locale non Unicode programs
猜你喜欢

During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution

Ego planner code parsing Bspline_ Optimizer section (2)

2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】

Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities

Php based campus lost and found platform (automatic matching push)
![[optics] vortex generation based on MATLAB [including Matlab source code 1927]](/img/9b/b7f462e2ecbff0cee35e7de5c80cf7.jpg)
[optics] vortex generation based on MATLAB [including Matlab source code 1927]

Basic principle of LSM tree

Chapter 1: find all factorial sums, Grand Prix site unified programming, three factorial sums, graphic point scanning, recursive factorial n of n!, Find the factorial n of n!, King Shehan miscalculate

【光学】基于matlab介电常数计算【含Matlab源码 1926期】

【LeetCode】【SQL】刷题笔记
随机推荐
ActiveMQ的基础
PR FAQ: how to set PR vertical screen sequence?
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
Flume learning notes
Why should the gradient be manually cleared before back propagation in pytorch?
Win10 share you don't have permission
Comments on flowable source code (37) asynchronous job processor
第一章:拓广同码小数和s(d, n)
The earliest record
04 -- QT OpenGL two sets of shaders draw two triangles
Summary of composition materials for 2020 high-frequency examination center of educational resources
The space of C disk is insufficient, and the computer becomes stuck. Quickly expand the capacity of C disk to make the system more smooth
Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities
Ego planner code parsing Bspline_ Optimizer section (2)
01 - QT OpenGL display OpenGL window
P3402 persistent and searchable
Sentinel source code analysis part I sentinel overview
Record the errors reported when running fluent in the simulator
How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
[disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]