CTF_Crypto打卡

RSA1

下载附件发现是一个非常简单的RSA加密

e = 65537
N = 1018261336751023520497560395829454421245429586704872293236600679847605951423419167478189648109263
the encrypted flag  = 713822463491939628949080236459794906441914407944768290378695739068636927695199214947719158013040

首先对于大整数进行分解,大整数分解

p=9942874965373398689
q=102411157768469768587484356311902427789461430190314198242306101223897141593967

利用RSA的原理对其破解,详细可以查看https://mp.csdn.net/mp_blog/creation/editor/134606261

解密代码

import gmpy2
from Crypto.Util.number import *
p=9942874965373398689
q=102411157768469768587484356311902427789461430190314198242306101223897141593967
n=p*q
dn=(p-1)*(q-1)
e=65537
encflag=713822463491939628949080236459794906441914407944768290378695739068636927695199214947719158013040
d=gmpy2.invert(e,dn)
print(long_to_bytes(pow(encflag,d,n)))

解密结果

shellmates{U_5h0uld_U53_L4rg3_Numb3r5}

unrecovery

题目

import random 
from string import ascii_lowercase,digits
from secret import flag

chars = ascii_lowercase + digits 

random.seed(2**1337 - 1)#加一个种子

shuffled_chars=[i for i in chars]
random.shuffle(shuffled_chars)#将字符串chars打乱
shuffled_chars = ''.join(shuffled_chars)
#print(f"{chars}\n{''.join(shuffled_chars)}");input()

enc = ''
for i in flag:
    if i.isalnum():#如果i为字母和数字返回ture,反之返回false
        enc += shuffled_chars[chars.index(i)]
    else:
        enc+=i

print(enc)
#  ctn44vmunc{3ghgsy_uto_coo2_gc_2asyoxg1ec}

就一个简单字符串之间的转换问题,由于种子已经给出了,所以可以直接得出,不多说直接上代码

from string import ascii_lowercase,digits
import random

chars = ascii_lowercase + digits
print(chars)
random.seed(2**1337 - 1)

shuffled_chars=[i for i in chars]
random.shuffle(shuffled_chars)
shuffled_chars = ''.join(shuffled_chars)
print(shuffled_chars)
dec = ''
enc="ctn44vmunc{3ghgsy_uto_coo2_gc_2asyoxg1ec}"
for i in enc:
    if i.isalnum():#字母和数字返回ture
        dec +=chars[shuffled_chars.index(i)]
    else:
        dec+=i

print(dec)
#

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值