[RoarCTF2019]RSA

1.题目

# A=(((y%x)**5)%(x%y))**2019+y**316+(y+1)/x
# p=next_prime(z*x*y)
# q=next_prime(z)
# A =  2683349182678714524247469512793476009861014781004924905484127480308161377768192868061561886577048646432382128960881487463427414176114486885830693959404989743229103516924432512724195654425703453612710310587164417035878308390676612592848750287387318129424195208623440294647817367740878211949147526287091298307480502897462279102572556822231669438279317474828479089719046386411971105448723910594710418093977044179949800373224354729179833393219827789389078869290217569511230868967647963089430594258815146362187250855166897553056073744582946148472068334167445499314471518357535261186318756327890016183228412253724
# n =  117930806043507374325982291823027285148807239117987369609583515353889814856088099671454394340816761242974462268435911765045576377767711593100416932019831889059333166946263184861287975722954992219766493089630810876984781113645362450398009234556085330943125568377741065242183073882558834603430862598066786475299918395341014877416901185392905676043795425126968745185649565106322336954427505104906770493155723995382318346714944184577894150229037758434597242564815299174950147754426950251419204917376517360505024549691723683358170823416757973059354784142601436519500811159036795034676360028928301979780528294114933347127
# c =  41971850275428383625653350824107291609587853887037624239544762751558838294718672159979929266922528917912189124713273673948051464226519605803745171340724343705832198554680196798623263806617998072496026019940476324971696928551159371970207365741517064295956376809297272541800647747885170905737868568000101029143923792003486793278197051326716680212726111099439262589341050943913401067673851885114314709706016622157285023272496793595281054074260451116213815934843317894898883215362289599366101018081513215120728297131352439066930452281829446586562062242527329672575620261776042653626411730955819001674118193293313612128

2.复现

直接分解n,发现可以分解,然后就爆破e。

 

 

import gmpy2
import libnum
import sympy
A =  2683349182678714524247469512793476009861014781004924905484127480308161377768192868061561886577048646432382128960881487463427414176114486885830693959404989743229103516924432512724195654425703453612710310587164417035878308390676612592848750287387318129424195208623440294647817367740878211949147526287091298307480502897462279102572556822231669438279317474828479089719046386411971105448723910594710418093977044179949800373224354729179833393219827789389078869290217569511230868967647963089430594258815146362187250855166897553056073744582946148472068334167445499314471518357535261186318756327890016183228412253724
n =  117930806043507374325982291823027285148807239117987369609583515353889814856088099671454394340816761242974462268435911765045576377767711593100416932019831889059333166946263184861287975722954992219766493089630810876984781113645362450398009234556085330943125568377741065242183073882558834603430862598066786475299918395341014877416901185392905676043795425126968745185649565106322336954427505104906770493155723995382318346714944184577894150229037758434597242564815299174950147754426950251419204917376517360505024549691723683358170823416757973059354784142601436519500811159036795034676360028928301979780528294114933347127
c =  41971850275428383625653350824107291609587853887037624239544762751558838294718672159979929266922528917912189124713273673948051464226519605803745171340724343705832198554680196798623263806617998072496026019940476324971696928551159371970207365741517064295956376809297272541800647747885170905737868568000101029143923792003486793278197051326716680212726111099439262589341050943913401067673851885114314709706016622157285023272496793595281054074260451116213815934843317894898883215362289599366101018081513215120728297131352439066930452281829446586562062242527329672575620261776042653626411730955819001674118193293313612128
p=842868045681390934539739959201847552284980179958879667933078453950968566151662147267006293571765463137270594151138695778986165111380428806545593588078365331313084230014618714412959584843421586674162688321942889369912392031882620994944241987153078156389470370195514285850736541078623854327959382156753458569
q=139916095583110895133596833227506693679306709873174024876891023355860781981175916446323044732913066880786918629089023499311703408489151181886568535621008644997971982182426706592551291084007983387911006261442519635405457077292515085160744169867410973960652081452455371451222265819051559818441257438021073941183
phi=(p-1)*(q-1)
# 爆破e
for e in range(100000):
    if(gmpy2.gcd(e,phi)==1):
        d=gmpy2.invert(e,phi)
        m=pow(c,d,n)
        flag=libnum.n2s(int(m))
        if('CTF' in str(flag)):
            print(flag)
            break
# b'RoarCTF{wm-l1l1ll1l1l1l111ll}'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
以下是使用 C++ 编写的基于 OpenSSL 库的 RSA 加密示例代码: ```cpp #include <iostream> #include <string> #include <openssl/rsa.h> #include <openssl/pem.h> #include <openssl/err.h> using namespace std; int main() { string plaintext = "Hello, World!"; // 待加密的明文 string public_key_file = "public_key.pem"; // 公钥文件路径 // 读取公钥文件 FILE* fp = fopen(public_key_file.c_str(), "rb"); if (!fp) { cerr << "Failed to open public key file" << endl; return -1; } RSA* rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL); fclose(fp); if (!rsa) { cerr << "Failed to load public key" << endl; ERR_print_errors_fp(stderr); return -1; } // 加密 int rsa_len = RSA_size(rsa); // 计算 RSA 公钥长度 unsigned char* ciphertext = new unsigned char[rsa_len]; int ciphertext_len = RSA_public_encrypt( plaintext.size(), // 明文长度 (const unsigned char*)plaintext.c_str(), // 明文内容 ciphertext, // 加密后的密文 rsa, // 公钥 RSA_PKCS1_PADDING // 填充方式 ); if (ciphertext_len == -1) { cerr << "Failed to encrypt" << endl; ERR_print_errors_fp(stderr); return -1; } // 打印加密结果 cout << "Ciphertext: "; for (int i = 0; i < ciphertext_len; i++) { printf("%02x", ciphertext[i]); } cout << endl; delete[] ciphertext; RSA_free(rsa); return 0; } ``` 需要注意的是,使用 OpenSSL 库进行 RSA 加密需要安装 OpenSSL 开发库并在编译时链接该库。在 Windows 平台下,可以使用 vcpkg 进行安装和管理。例如,使用以下命令安装 OpenSSL 开发库: ``` vcpkg install openssl ``` 然后在 VS2019 中指定 vcpkg 安装目录下的 OpenSSL 头文件和库文件路径,并在链接器设置中添加 OpenSSL 库文件的名称,即可成功编译上述代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

T1M@

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值