zoukankan      html  css  js  c++  java
  • UNCTF2020-crypto:easy_ras

    附件:

    from Crypto.Util import number
    import gmpy2
    from Crypto.Util.number import bytes_to_long
    
    p = number.getPrime(1024)
    q = number.getPrime(1024)
    if p > q:
        a = p + q
        b = p - q
        print(a,b)
    
    n = p * q
    e = 65537
    phi = (p-1)*(q-1)
    d = gmpy2.invert(e,phi)
    m = bytes_to_long(b'msg')
    c = pow(m,e,n)
    print(c)
    
    #320398687477638913975700270017132483556404036982302018853617987417039612400517057680951629863477438570118640104253432645524830693378758322853028869260935243017328300431595830632269573784699659244044435107219440036761727692796855905230231825712343296737928172132556195116760954509270255049816362648350162111168
    #9554090001619033187321857749048244231377711861081522054479773151962371959336936136696051589639469653074758469644089407114039221055688732553830385923962675507737607608026140516898146670548916033772462331195442816239006651495200436855982426532874304542570230333184081122225359441162386921519665128773491795370
    #22886015855857570934458119207589468036427819233100165358753348672429768179802313173980683835839060302192974676103009829680448391991795003347995943925826913190907148491842575401236879172753322166199945839038316446615621136778270903537132526524507377773094660056144412196579940619996180527179824934152320202452981537526759225006396924528945160807152512753988038894126566572241510883486584129614281936540861801302684550521904620303946721322791533756703992307396221043157633995229923356308284045440648542300161500649145193884889980827640680145641832152753769606803521928095124230843021310132841509181297101645567863161780

    解密脚本:

    from Crypto.Util import number
    import gmpy2
    from Crypto.Util.number import bytes_to_long
    from binascii import a2b_hex
    a=320398687477638913975700270017132483556404036982302018853617987417039612400517057680951629863477438570118640104253432645524830693378758322853028869260935243017328300431595830632269573784699659244044435107219440036761727692796855905230231825712343296737928172132556195116760954509270255049816362648350162111168
    b=9554090001619033187321857749048244231377711861081522054479773151962371959336936136696051589639469653074758469644089407114039221055688732553830385923962675507737607608026140516898146670548916033772462331195442816239006651495200436855982426532874304542570230333184081122225359441162386921519665128773491795370
    c=22886015855857570934458119207589468036427819233100165358753348672429768179802313173980683835839060302192974676103009829680448391991795003347995943925826913190907148491842575401236879172753322166199945839038316446615621136778270903537132526524507377773094660056144412196579940619996180527179824934152320202452981537526759225006396924528945160807152512753988038894126566572241510883486584129614281936540861801302684550521904620303946721322791533756703992307396221043157633995229923356308284045440648542300161500649145193884889980827640680145641832152753769606803521928095124230843021310132841509181297101645567863161780
    q=(a-b)//2
    p=a-q
    n=q*p
    e = 65537
    print(q)
    print(p)
    '''
        a = p + q
        b = p - q
    
        a-b=p+q-p+q
        a-b=2q
    '''
    #c = pow(m,e,n)
    
    phi_n = (p-1)*(q-1)
    d = gmpy2.invert(e,phi_n)
    #print(d)
    
    flag = a2b_hex(hex(pow(c,d,n))[2:])
    print(flag)
  • 相关阅读:
    一款你不容错过的Laravel后台管理扩展包 —— Voyager
    关于后台动态模板添加内容的总结 Builder使用
    Python 解决 :NameError: name 'reload' is not defined 问题
    thinkcmf,thinksns,thinkphp,onethink三者是什么关系?
    PHP中用下划线开头的变量含义
    NetBeans 时事通讯(刊号 # 77 Oct 21, 2009)
    NetBeans 时事通讯(刊号 # 78 Oct 27, 2009)
    最受欢迎的中国 50 技术博客评选结果
    祝父亲生日快乐
    最受欢迎的中国 50 技术博客评选结果
  • 原文地址:https://www.cnblogs.com/luocodes/p/13986249.html
Copyright © 2011-2022 走看看