码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • buuctf crypto 【[HDCTF2019]basic rsa】解题记录


    1.打开文件

    2.套用脚本

    import random
    from binascii import a2b_hex,b2a_hex
    p = 262248800182277040650192055439906580479
    q = 262854994239322828547925595487519915551
    n = p * q
    def multiplicative_inversr(a,b):
        x = 0
        y = 1
        lx = 1
        ly = 0
        oa = a
        ob = b
        while b != 0:
            q = a // b
            (a, b) = (b, a % b)
            (x, lx) = ((lx - (q * x)), x)
            (y, ly) = ((ly - (q * y)), y)
        if lx < 0:
            lx += ob
        if ly < 0:
            ly += oa
        return lx
    def gcd(a,b):
        while b != 0:
            a, b = b, a % b
        return a
    def generate_keypair(p,q):
        n = p * q
        phi = (p - 1) * (q -1)
        e = 65533
        g = gcd(e, phi)
        while g != 1:
            e = random.randrange(1, phi)
            g = gcd(e, phi)
        d = multiplicative_inversr(e, phi)
        return ((e,n),(d,n))
    def encrypt(pk, plaintext):
        key, n = pk[0]
        print(b2a_hex(plaintext.encode()))
        cipher = pow(int(b2a_hex(plaintext.encode()),16), key , n)
        return cipher
    def decrypt(pk, cipher):
        key, n = pk[1]
        cipher = pow(cipher, key ,n)
        cipher = a2b_hex(hex(cipher).split('0x')[1])
        return cipher
    pk = generate_keypair(p,q)
    cipher = 27565231154623519221597938803435789010285480123476977081867877272451638645710
    plaintext = decrypt(pk, cipher)
    print(plaintext)

    3.运行,得到flag

  • 相关阅读:
    Lambda表达式,Stream流
    封装了一个简单的C++ HDF5工具库,实现常用数据类型的读写
    我整理了近五年的开发者报告,看看国内外有什么差异?
    两招提升硬盘存储数据的写入效率
    C++ Reference: Standard C++ Library reference: C Library: cwchar: swscanf
    Java练习题-输出斐波那契(Fibonacci)数列
    Java代码中如何向HashMap对象中添加(Map集合对象)呢?
    springboot整合FTP实现文件传输
    跨境电商年底风控升级,测评养号如何选择稳定且纯净的IP环境?
    Qt/C++编写视频监控系统81-Onvif报警抓图和录像并回放
  • 原文地址:https://blog.csdn.net/jsbbd12/article/details/132805555
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号