实验吧RSAROLL wp

根据题目  TaiChi-Team.com

{920139713,19}
 
704796792
752211152
274704164
18414022
368270835
483295235
263072905
459788476
483295235
459788476
663551792
475206804
459788476
428313374
475206804
459788476
425392137
704796792
458265677
341524652
483295235
534149509
425392137
428313374
425392137
341524652
458265677
263072905
483295235
828509797
341524652
425392137
475206804
428313374
483295235
475206804
459788476

306220148

 

可知:n=920139713

e=19

c=[704796792,……​]

目标:密文解密序列 [m1,m2……]

思路:

分解n,得p,q 根据p,q 获得欧拉数,根据欧拉数 获得 d,根据d 获得m

步骤:

1. 分解n 得 p,q

 

def crackN(n):
    i=2
    while i

2. 根据p,q获得欧拉数

 

 

o_n=int(p-1)*int((n/p)-1)

3.根据扩展欧几里得算法 获得 d

 

 

def exgcd(m,n,x,y):
        if n == 0:
                x = 1
                y = 0
                return (m,x,y)
        a1 = b = 1
        a = b1 = 0
        c = m
        d = n
        q = int(c/d)
        r = c%d
        while r:
                c = d
                d = r
                t = a1
                a1 = a
                a = t-q*a
                t = b1
                b1 = b
                b = t-q*b
                q = int(c/d)
                r = c%d
        x = a
        y = b
        return (d,x,y)

返回值为数组,y为rsa 算法中的d

 

 

d=exgcd(o_n,e,0,0)[2]

4.根据d解密密文c获得m

 

 

chr(pow(c,d,n))

5.遍历密文数组c获得m序列

 

 

s=""
while k

 

 

完整脚本:

 

e=19
n=920139713
c=[
704796792,
752211152,
274704164,
18414022,
368270835,
483295235,
263072905,
459788476,
483295235,
459788476,
663551792,
475206804,
459788476,
428313374,
475206804,
459788476,
425392137,
704796792,
458265677,
341524652,
483295235,
534149509,
425392137,
428313374,
425392137,
341524652,
458265677,
263072905,
483295235,
828509797,
341524652,
425392137,
475206804,
428313374,
483295235,
475206804,
459788476,
306220148,
]
def exgcd(m,n,x,y):
        if n == 0:
                x = 1
                y = 0
                return (m,x,y)
        a1 = b = 1
        a = b1 = 0
        c = m
        d = n
        q = int(c/d)
        r = c%d
        while r:
                c = d
                d = r
                t = a1
                a1 = a
                a = t-q*a
                t = b1
                b1 = b
                b = t-q*b
                q = int(c/d)
                r = c%d
        x = a
        y = b
        return (d,x,y)
def crackN(n):
    i=2
    while i

计算获得最终结果:

 

 

flag{13212je2ue28fy71w8u87y31r78eu1e2}

 

 

 

你可能感兴趣的:(实验吧RSAROLL wp)