首页 > 其他分享 >BaseCTF2024-week1-Crypto部分题目wp

BaseCTF2024-week1-Crypto部分题目wp

时间:2024-08-24 23:37:39浏览次数:13  
标签:BaseCTF2024 Crypto 0cc175b9c0f1b6a831c399e269772661 wp print import my md5

先放一下官方的wp(我这里只放我出的题):

Docs (feishu.cn)

babypack

from Crypto.Util.number import *
import random
flag=b'BaseCTF{}'
m=bytes_to_long(flag)
bin_m=bin(m)[2:]
length=len(bin_m)

a=[1]
sum=1
for i in range(length-1):
    temp=random.randint(2*sum+1,4*sum)
    sum=sum+temp
    a.append(temp)

a=a[::-1]
c=0
for i in range(length):
    if bin_m[i]=='1':
        c=c+a[i]
print("a=",a)
print("c=",c)

简单的超递增序列(不懂的可以简单了解一下背包密码)

从尾开始遍历列表a,大于c就为0,小于等于c就为1,并且c要减去这个值

(数据太多我就不贴了)

#BaseCTF{2c4b0c15-3bee-4e4a-be6e-0f21e44bd4c9}
from Crypto.Util.number import *
a=
c=2488656295807929935404316556194747314175977860755594014838879551525915558042003735363919054632036359039039831854134957725034750353847782168033537523854288427613513938991943920607437000388885418821419115067060003426834
bin_m=""
for i in a:
    if c>=i:
        bin_m+="1"
        c=c-i
    else:
        bin_m+="0"
m=int(bin_m,2)
print(long_to_bytes(m))

babyrsa

from Crypto.Util.number import *

flag=b'BaseCTF{}'
m=bytes_to_long(flag)

n=getPrime(1024)
e=65537
c=pow(m,e,n)

print("n =",n)
print("e =",e)
print("c =",c)
"""
n = 104183228088542215832586853960545770129432455017084922666863784677429101830081296092160577385504119992684465370064078111180392569428724567004127219404823572026223436862745730173139986492602477713885542326870467400963852118869315846751389455454901156056052615838896369328997848311481063843872424140860836988323
e = 65537
c = 82196463059676486575535008370915456813185183463924294571176174789532397479953946434034716719910791511862636560490018194366403813871056990901867869218620209108897605739690399997114809024111921392073218916312505618204406951839504667533298180440796183056408632017397568390899568498216649685642586091862054119832
"""

单素数RSA

\[\phi(n)$$表示从1到n之间,有多少个数与n互素。 计算方法:排除掉不与n互素的数。 $$\phi(pq)=pq-p-q+1 = (p-1)(q-1)\]

这题n已经是素数了,1到n-1都与n互素,$$\phi(n)=n-1$$

求到$$\phi$$之后就正常做就行

(理解RSA最重要的一点是搞懂e*d=1 mod(φ(n)),要理解为什么这里为什么是取φ(n))

(很难绷,为什么那么多人问我n怎么分解,n=getPrime(1024)已经是素数了,不需要分解了。)

from Crypto.Util.number import *
import gmpy2
n = 104183228088542215832586853960545770129432455017084922666863784677429101830081296092160577385504119992684465370064078111180392569428724567004127219404823572026223436862745730173139986492602477713885542326870467400963852118869315846751389455454901156056052615838896369328997848311481063843872424140860836988323
e = 65537
c = 82196463059676486575535008370915456813185183463924294571176174789532397479953946434034716719910791511862636560490018194366403813871056990901867869218620209108897605739690399997114809024111921392073218916312505618204406951839504667533298180440796183056408632017397568390899568498216649685642586091862054119832

phin=n-1
d=gmpy2.invert(e,phin)
m=pow(c,d,n)
print(long_to_bytes(m))
#b'BaseCTF{7d7c90ae-1127-4170-9e0d-d796efcd305b}'

hellpCrypto

from Crypto.Util.number import *
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import random

flag=b'BaseCTF{}'

key=random.randbytes(16)
print(bytes_to_long(key))

my_aes=AES.new(key=key,mode=AES.MODE_ECB)
print(my_aes.encrypt(pad(flag,AES.block_size)))

# key1 = 208797759953288399620324890930572736628
# c = b'U\xcd\xf3\xb1 r\xa1\x8e\x88\x92Sf\x8a`Sk],\xa3(i\xcd\x11\xd0D\x1edd\x16[&\x92@^\xfc\xa9(\xee\xfd\xfb\x07\x7f:\x9b\x88\xfe{\xae'

直接AES解密即可

from Crypto.Util.number import *
from Crypto.Cipher import AES


key1 = 208797759953288399620324890930572736628
c = b'U\xcd\xf3\xb1 r\xa1\x8e\x88\x92Sf\x8a`Sk],\xa3(i\xcd\x11\xd0D\x1edd\x16[&\x92@^\xfc\xa9(\xee\xfd\xfb\x07\x7f:\x9b\x88\xfe{\xae'
my_aes1=AES.new(key=long_to_bytes(key1),mode=AES.MODE_ECB)
print(my_aes1.decrypt(c))

#b'BaseCTF{b80bf679-1869-4fde-b3f9-d51b872d31fb}\x03\x03\x03'

你会算md5吗

import hashlib

flag='BaseCTF{}'

output=[]
for i in flag:
    my_md5=hashlib.md5()
    my_md5.update(i.encode())
    output.append(my_md5.hexdigest())
print("output =",output)
'''
output = ['9d5ed678fe57bcca610140957afab571', '0cc175b9c0f1b6a831c399e269772661', '03c7c0ace395d80182db07ae2c30f034', 'e1671797c52e15f763380b45e841ec32', '0d61f8370cad1d412f80b84d143e1257', 'b9ece18c950afbfa6b0fdbfa4ff731d3', '800618943025315f869e4e1f09471012', 'f95b70fdc3088560732a5ac135644506', '0cc175b9c0f1b6a831c399e269772661', 'a87ff679a2f3e71d9181a67b7542122c', '92eb5ffee6ae2fec3ad71c777531578f', '8fa14cdd754f91cc6554c9e71929cce7', 'a87ff679a2f3e71d9181a67b7542122c', 'eccbc87e4b5ce2fe28308fd9f2a7baf3', '0cc175b9c0f1b6a831c399e269772661', 'e4da3b7fbbce2345d7772b0674a318d5', '336d5ebc5436534e61d16e63ddfca327', 'eccbc87e4b5ce2fe28308fd9f2a7baf3', '8fa14cdd754f91cc6554c9e71929cce7', '8fa14cdd754f91cc6554c9e71929cce7', '45c48cce2e2d7fbdea1afc51c7c6ad26', '336d5ebc5436534e61d16e63ddfca327', 'a87ff679a2f3e71d9181a67b7542122c', '8f14e45fceea167a5a36dedd4bea2543', '1679091c5a880faf6fb5e6087eb1b2dc', 'a87ff679a2f3e71d9181a67b7542122c', '336d5ebc5436534e61d16e63ddfca327', '92eb5ffee6ae2fec3ad71c777531578f', '8277e0910d750195b448797616e091ad', '0cc175b9c0f1b6a831c399e269772661', 'c81e728d9d4c2f636f067f89cc14862c', '336d5ebc5436534e61d16e63ddfca327', '0cc175b9c0f1b6a831c399e269772661', '8fa14cdd754f91cc6554c9e71929cce7', 'c9f0f895fb98ab9159f51fd0297e236d', 'e1671797c52e15f763380b45e841ec32', 'e1671797c52e15f763380b45e841ec32', 'a87ff679a2f3e71d9181a67b7542122c', '8277e0910d750195b448797616e091ad', '92eb5ffee6ae2fec3ad71c777531578f', '45c48cce2e2d7fbdea1afc51c7c6ad26', '0cc175b9c0f1b6a831c399e269772661', 'c9f0f895fb98ab9159f51fd0297e236d', '0cc175b9c0f1b6a831c399e269772661', 'cbb184dd8e05c9709e5dcaedaa0495cf']
'''

单字符md5,可以理解为单字节加密,没有行列转换混淆的话,一般都可以直接爆破

(如果答案不对一般就是字符集的问题,整数32-126就是可见字符范围)

import hashlib


output = ['9d5ed678fe57bcca610140957afab571', '0cc175b9c0f1b6a831c399e269772661', '03c7c0ace395d80182db07ae2c30f034', 'e1671797c52e15f763380b45e841ec32', '0d61f8370cad1d412f80b84d143e1257', 'b9ece18c950afbfa6b0fdbfa4ff731d3', '800618943025315f869e4e1f09471012', 'f95b70fdc3088560732a5ac135644506', '0cc175b9c0f1b6a831c399e269772661', 'a87ff679a2f3e71d9181a67b7542122c', '92eb5ffee6ae2fec3ad71c777531578f', '8fa14cdd754f91cc6554c9e71929cce7', 'a87ff679a2f3e71d9181a67b7542122c', 'eccbc87e4b5ce2fe28308fd9f2a7baf3', '0cc175b9c0f1b6a831c399e269772661', 'e4da3b7fbbce2345d7772b0674a318d5', '336d5ebc5436534e61d16e63ddfca327', 'eccbc87e4b5ce2fe28308fd9f2a7baf3', '8fa14cdd754f91cc6554c9e71929cce7', '8fa14cdd754f91cc6554c9e71929cce7', '45c48cce2e2d7fbdea1afc51c7c6ad26', '336d5ebc5436534e61d16e63ddfca327', 'a87ff679a2f3e71d9181a67b7542122c', '8f14e45fceea167a5a36dedd4bea2543', '1679091c5a880faf6fb5e6087eb1b2dc', 'a87ff679a2f3e71d9181a67b7542122c', '336d5ebc5436534e61d16e63ddfca327', '92eb5ffee6ae2fec3ad71c777531578f', '8277e0910d750195b448797616e091ad', '0cc175b9c0f1b6a831c399e269772661', 'c81e728d9d4c2f636f067f89cc14862c', '336d5ebc5436534e61d16e63ddfca327', '0cc175b9c0f1b6a831c399e269772661', '8fa14cdd754f91cc6554c9e71929cce7', 'c9f0f895fb98ab9159f51fd0297e236d', 'e1671797c52e15f763380b45e841ec32', 'e1671797c52e15f763380b45e841ec32', 'a87ff679a2f3e71d9181a67b7542122c', '8277e0910d750195b448797616e091ad', '92eb5ffee6ae2fec3ad71c777531578f', '45c48cce2e2d7fbdea1afc51c7c6ad26', '0cc175b9c0f1b6a831c399e269772661', 'c9f0f895fb98ab9159f51fd0297e236d', '0cc175b9c0f1b6a831c399e269772661', 'cbb184dd8e05c9709e5dcaedaa0495cf']
for i in output:
    for j in range(33,128):
        my_md5=hashlib.md5()
        my_md5.update(chr(j).encode())
        if  my_md5.hexdigest() == i:
            print(chr(j),end="")
            break
#BaseCTF{a4bf43a5-3ff9-4764-bda2-af8ee4db9a8a}

标签:BaseCTF2024,Crypto,0cc175b9c0f1b6a831c399e269772661,wp,print,import,my,md5
From: https://www.cnblogs.com/naby/p/18378496

相关文章

  • golang RSA 解密前端jsencrypt发送的数据时异常 crypto/rsa: decryption error 解决方
    golang中RSA解密前端(jsencrypt)发来的密文后出现 "crypto/rsa:decryptionerror" ,这个问题首先需要确认你的私匙和公匙是否匹配,如果匹配那检查入参数据类型,前端发送来的rsa加密后的数据一般都是经过base64编码后的,在后端进行RSA解码时需要对前端发送的数据进行base64......
  • WPF 的 await Application.Current.Dispatcher.InvokeAsync,Func 如果是Task , 等待赋
    最近在检查我们组内的代码,发现好多用到awaitApplication.Current.Dispatcher.InvokeAsync相信好多WPF的开发都会用到该方法做UI线程切换。但是细看里边的执行,发现了个别存在存在没有等待完成的情况  执行的结果是i为null值。这也就说明了执行了awaitApplica......
  • WPF XamlReader Load xaml and parse
    //ThexamlmaterialnamedMainWin.xaml<Windowxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.......
  • WPF ystem.Windows.Markup.XamlParseException HResult=0x80131501 Message='Spec
    System.Windows.Markup.XamlParseExceptionHResult=0x80131501Message='Specifiedclassname'WpfApp268.MainWindow'doesn'tmatchactualrootinstancetype'System.Windows.Window'.RemovetheClassdirectiveorprovideanin......
  • WPF 模仿前端大佬写一个Hover效果
    先看一下效果吧: 原博主的地址:【动画进阶】神奇的卡片Hover效果与Blur的特性探究-ChokCoco-博客园(cnblogs.com)原效果是一个css效果,我们采用WPF的方式模仿一下因为技术有限,没有原博主的那么好看,毕竟盗版永远比不过原版...然后这里看一下盗版的怎么写吧先是拿到......
  • JSP基于ssm的校园社团管理系统7wp38程序+源码+数据库+调试部署+开发环境
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表系统功能:用户,医生,医院类型,社区医院,接种疫苗,疫苗类型,预约信息开题报告内容一、项目背景与意义随着高等教育的快速发展,校园社团作为学生第二课堂的重要组......
  • WPF 模拟UWP原生窗口样式——亚克力|云母材质、自定义标题栏样式、原生DWM动画 (附我封
    先看一下最终效果,左图为使用亚克力材质并添加组合颜色的效果;右图为MicaAlt材质的效果。两者都自定义了标题栏并且最大限度地保留了DWM提供的原生窗口效果(最大化最小化、关闭出现的动画、窗口阴影、拖拽布局器等)。接下来把各部分的实现一个个拆开来讲讲。一、使用窗口材质特......
  • 如何在word/wps中添加代码,并且保持源代码风格
    一、HighlightCode在线工具https://highlightcode.com二、操作步骤1、将代码复制到框中 2、点击右上方的高亮代码 3、得到如下代码样式 4、将代码复制到Word/Wps中即可,效果如下图所示 ......
  • WPF 设备输入事件封装
    本文主要介绍WPF应用对鼠标输入、触摸屏触笔以及触摸事件的封装之前有简单说明设备输入类型 WPF屏幕点击的设备类型-唐宋元明清2188-博客园(cnblogs.com)1、鼠标- 通过Mouse相关的事件参数MouseButtonEventArgs中的数据,e.StylusDecice==null表示没有触摸设备,所以设备为......
  • WPF中如何使用后台代码动态创建数据模板(DataTemplate)
    数据模板回顾 在WPF中数据模板可以控制数据的呈现方式。对于一些简单的数据,例如一个string,一个int,在显示时,无须额外控制。但是对于复杂数据类型,就需要使用数据模板来控制数据的呈现方式。 一个很简单的例子假设我们定义了一个学生类1publicclassStudent2......