python codegate_prelliminary_2018 RSABaby WriteUp

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python codegate_prelliminary_2018 RSABaby WriteUp相关的知识,希望对你有一定的参考价值。

'''
RSA Baby Payload

req.

    egcd(a,b) -> s, t
    modInv(a, b) -> inv
'''

def gcd(a, b):
    if b > a:
        tmp = a
        a = b
        b = tmp
    while b != 0:
        tmp = b
        b = a%b
        a = tmp
    return a
# egcd
def modInv(b, a):
    if a > b:
        r = [a, b]
        s = [0, 1]
    else:
        r = [b, a]
        s = [1, 0]
    while r[1] != 0:
        q = r[0] // r[1]
        r.append(r[0] - q * r[1])
        del r[0]
        s.append(s[0] - q * s[1])
        del s[0]
    if s[0] < 0:
        s[0] += a
    return s[0]

N =
e = 65537
g = 
enc_flag = 

p = gcd(pow(2, (e*g) + (0xdeadbeaf-1), N)-1, N)
q = N//p

piN = (p-1)*(q-1)
d = modInv(e, piN)

print("Priv : " + str(d))
flag = pow(enc_flag, d, N)

print(hex(flag)[2:-1].decode('hex')) 

以上是关于python codegate_prelliminary_2018 RSABaby WriteUp的主要内容,如果未能解决你的问题,请参考以下文章

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python

python初识