DASCTF-CBCTF-2023 Crypto部分复现

文章目录

    • EzRSA
    • CB backpack

这次比赛没打,记错时间了,看了一下,如果去做的话大概也只能做出那两道简单的题,还是太菜啦

EzRSA

题目描述:

from Crypto.Util.number import *
import random
from gmpy2 import *
from libnum import *
from flag import flagdef padding(f):random_chars = bytes([random.randint(0, 255) for _ in range(32)])f = f + random_charsreturn fdef guess_p(p):e = 65537P = pn1 = getPrime(512)*getPrime(512)with open('enc.txt', 'w+') as f:while jacobi(2,n1) == 1:n1 = getPrime(512)*getPrime(512)while P:pad = random.randint(0, 2**2023)**2 message = pad << 1 + P % 2cipher = pow(message, e, n1)f.write(str(cipher)+'n')P //= 2print("n1 = "+ str(n1) )    def guess_q(q):def encrypt(q, n):e = random.randint(1000,2000)noise = random.randint(0, n - 1)c = pow(q+noise,e,n)return e, noise,c n2 = getPrime(512)*getPrime(512)e1, noise1, c1 = encrypt(q, n2)e2, noise2, c2 = encrypt(q, n2)print("n2 = "+ str(n2) ) print('(e1, noise1, c1) =', (e1,noise1,c1))print('(e2, noise2, c2) =', (e2,noise2,c2))
p = getPrime(512)
q = getPrime(512)n = p*q
guess_p(p)
guess_q(q)
e = 0x10001
flag = padding(flag)
m = bytes_to_long(flag)
c = pow(m,e,n)print("c = " + str(c))
'''
n1 = 65634094430927080732256164808833233563732628654160389042977689628512527168256899310662239009610512772020503283842588142453533499954947692968978190310627721338357432052800695091789711809256924541784954080619073213358228083200846540676931341013554634493581962527475555869292091755676130810562421465063412235309
n2 = 103670293685965841863872863719573676572683187403862749665555450164387906552249974071743238931253290278574192713467491802940810851806104430306195931179902098180199167945649526235613636163362672777298968943319216325949503045377100235181706964846408396946496139224344270391027205106691880999410424150216806861393
(e1, noise1, c1) = (1743, 44560588075773853612820227436439937514195680734214431948441190347878274184937952381785302837541202705212687700521129385632776241537669208088777729355349833215443048466316517110778502508209433792603420158786772339233397583637570006255153020675167597396958251208681121668808253767520416175569161674463861719776, 65643009354198075182587766550521107063140340983433852821580802983736094225036497335607400197479623208915379722646955329855681601551282788854644359967909570360251550766970054185510197999091645907461580987639650262519866292285164258262387411847857812391136042309550813795587776534035784065962779853621152905983)
(e2, noise2, c2) = (1325, 35282006599813744140721262875292395887558561517759721467291789696459426702600397172655624765281531167221787036009507833425145071265739486735993631460189629709591456017092661028839951392247601628468621576100035700437892164435424035004463142959219067199451575338270613300215815894328788753564798153516122567683, 50327632090778183759544755226710110702046850880299488259739672542025916422119065179822210884622225945376465802069464782311211031263046593145733701591371950349735709553105217501410716570601397725812709771348772095131473415552527749452347866778401205442409443726952960806789526845194216490544108773715759733714)
c = 124349762993424531697403299350944207725577290992189948388824124986066269514204313888980321088629462472088631052329128042837153718129149149661961926557818023704330462282009415874674794190206220980118413541269327644472633791532767765585035518183177197863522573410860341245613331398610013697803459403446614221369
'''

题目分析:
gen_q:
看到jacobi(2,n1)便知道是二次剩余的知识
c = ( 2 ∗ a 2 ) e ,当 P % 2 = 0 c = ( 2 ∗ a 2 + 1 ) e ,当 P % 2 = 1 c ( n 1 − 1 ) / / 2 ≡ ( 2 ∗ a 2 ) e ∗ ( n 1 − 1 ) / / 2 ≡ − 1 ∗ 1 m o d n 1 ⇒ j a c o b i ( e n c i , n 1 ) = − 1 , p = 0 + p c = (2 * a^2)^e ,当P \% 2 = 0\\ c = (2 * a^2 + 1)^e,当P \% 2 = 1\\ c^{(n1 - 1) // 2} \equiv (2 * a^2)^{e *(n1 - 1) //2} \equiv -1 * 1 \mod n1\\ \Rightarrow jacobi(enc_i,n1) = -1,p = 0 + p\\ c=(2a2)e,当P%2=0c=(2a2+1)e,当P%2=1c(n11)//2(2a2)e(n11)//211modn1jacobi(enci,n1)=1,p=0+p
gen_q:
相关消息攻击直接解啦

exp:

import binascii
import libnum
from gmpy2 import *
from Crypto.Util.number import *
n1 = 65634094430927080732256164808833233563732628654160389042977689628512527168256899310662239009610512772020503283842588142453533499954947692968978190310627721338357432052800695091789711809256924541784954080619073213358228083200846540676931341013554634493581962527475555869292091755676130810562421465063412235309
(e1, noise1, c1) = (1743, 44560588075773853612820227436439937514195680734214431948441190347878274184937952381785302837541202705212687700521129385632776241537669208088777729355349833215443048466316517110778502508209433792603420158786772339233397583637570006255153020675167597396958251208681121668808253767520416175569161674463861719776, 65643009354198075182587766550521107063140340983433852821580802983736094225036497335607400197479623208915379722646955329855681601551282788854644359967909570360251550766970054185510197999091645907461580987639650262519866292285164258262387411847857812391136042309550813795587776534035784065962779853621152905983)
(e2, noise2, c2) = (1325, 35282006599813744140721262875292395887558561517759721467291789696459426702600397172655624765281531167221787036009507833425145071265739486735993631460189629709591456017092661028839951392247601628468621576100035700437892164435424035004463142959219067199451575338270613300215815894328788753564798153516122567683, 50327632090778183759544755226710110702046850880299488259739672542025916422119065179822210884622225945376465802069464782311211031263046593145733701591371950349735709553105217501410716570601397725812709771348772095131473415552527749452347866778401205442409443726952960806789526845194216490544108773715759733714)
c = 124349762993424531697403299350944207725577290992189948388824124986066269514204313888980321088629462472088631052329128042837153718129149149661961926557818023704330462282009415874674794190206220980118413541269327644472633791532767765585035518183177197863522573410860341245613331398610013697803459403446614221369
n2 = 103670293685965841863872863719573676572683187403862749665555450164387906552249974071743238931253290278574192713467491802940810851806104430306195931179902098180199167945649526235613636163362672777298968943319216325949503045377100235181706964846408396946496139224344270391027205106691880999410424150216806861393ciphers = []
with open('enc.txt') as f:for line in f.read().split('n'):if line.strip():ciphers.append(int(line.strip()))p = ''
for i in ciphers:if jacobi(i,n1) == -1:p = '0' + pelse:p = '1' + pp = int(p,2)def franklinReiter(n,e1,e2,c1,c2,noise1,noise2):PR.<x> = PolynomialRing(Zmod(n))g1 = (x + noise1)^e1 - c1g2 = (x + noise2)^e2 - c2def gcd(g1, g2):while g2:g1, g2 = g2, g1 % g2return g1.monic() # return -gcd(g1, g2)[0]q=franklinReiter(n2,e1,e2,c1,c2,noise1,noise2)
q = 13189337905641321257372188436353844418280745284875462357019668708167547026960641869513283218672677712590326347601424108528959315675307896082223561007980457
p = 9473204278465588641589315677772678997836862033858760337441231265335880892205102590571357305720744128962068300763212493598006400853597404586755248901932203
e = 0x10001
phi = (p - 1) * (q - 1)
d = inverse(e,phi)
print(long_to_bytes(int(pow(c,d,p * q))))
# DASCTF{W05-y03r_m2st1r-j2c0b1_2nd_p01yn0mi2l!}

CB backpack

题目描述:

from random import shuffledef gen_e():e = []for i in range(8):ee = [0]*3+[1]*3shuffle(ee)e += eereturn ee = gen_e()
nbit = len(e) # 48
flag = 'DASCTF{'+sha256(''.join([str(i) for i in e]).encode()).hexdigest()+'}'a = [randint(1,2^nbit) for i in range(nbit)]re = 0
for i in range(nbit):re += e[i]*a[i]print(a)
print(re)

题目分析:
一开始看到,感觉很熟悉啊,这不妥妥的背包加密吗,结果。。。是我想简单了
又涉及到了知识盲区,跟着大佬的wp做了一遍,学习到了
总的来说就是数据给的不够大,直接用背包格解出不来,需要爆破几位,通过jsdn测试密度是否达标(d < 0.9408)
测试了一下,得爆破10位以上才能出结果,尽管爆破8位也满足d < 0.9408,但确实是得不到
这样的话我爆破12位吧

from math import *
n = 37
a = [65651991706497, 247831871690373, 120247087605020, 236854536567393, 38795708921144, 256334857906663, 120089773523233, 165349388120302, 123968326805899, 79638234559694, 259559389823590, 256776519514651, 107733244474073, 216508566448440, 39327578905012, 118682486932022, 263357223061004, 132872609024098, 44605761726563, 24908360451602, 237906955893793, 204469770496199, 7055254513808, 221802659519968, 169686619990988, 23128789035141, 208847144870760, 272339624469135, 269511404473473, 112830627321371, 73203551744776, 42843503010671, 118193938825623, 49625220390324, 230439888723036, 241486656550572, 107149406378865, 233503862264755, 269502011971514, 181805192674559, 152612003195556, 184127512098087, 165959151027513, 188723045133473, 241615906682300, 216101484550038, 81190147709444, 124498742419309]
a = a[11:]
d = n / log2(max(a))
N = ceil(1 / 2 * sqrt(n))
assert d < 0.9408, f"Density should be less than 0.9408 but was {d}."
print(d) # 0.7715984980953817

为了节省时间这里直接逆序,很快,几分钟就出来了

from tqdm import tqdm
a=[65651991706497, 247831871690373, 120247087605020, 236854536567393, 38795708921144, 256334857906663, 120089773523233, 165349388120302, 123968326805899, 79638234559694, 259559389823590, 256776519514651, 107733244474073, 216508566448440, 39327578905012, 118682486932022, 263357223061004, 132872609024098, 44605761726563, 24908360451602, 237906955893793, 204469770496199, 7055254513808, 221802659519968, 169686619990988, 23128789035141, 208847144870760, 272339624469135, 269511404473473, 112830627321371, 73203551744776, 42843503010671, 118193938825623, 49625220390324, 230439888723036, 241486656550572, 107149406378865, 233503862264755, 269502011971514, 181805192674559, 152612003195556, 184127512098087, 165959151027513, 188723045133473, 241615906682300, 216101484550038, 81190147709444, 124498742419309]
re=4051501228761632
A = a[12:]
bits=36
def ju(j):for i in j:if abs(i)!=1:return 0return 1
for i in tqdm(range(2^12,1,-1)):temp=[int(j) for j in bin(i)[2:].zfill(12)]t1,t2=temp[:6],temp[6:12]if sum(t1)!=3 or sum(t2)!=3:continuerr = sum([i*j for i,j in zip(temp,a[:12])])new_re = re - rrM=Matrix(ZZ,bits+1)for i in range(bits):M[i,i]=2M[i,-1]=A[i]for i in range(bits):M[-1,i]=1M[-1,-1]=new_reres=M.LLL()if ju(res[0][:-1]):print('find')print(temp)print(res[0])break

在这里插入图片描述
CB ezDHKE
这题很常见也很简单就不说了
CB curve
CB cipher
这两题等有时间再继续复现吧

学习到了爆破+背包格

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/167684.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

屏幕截图软件Snagit 2023 mac中文特点介绍

Snagit 2023 mac是一款屏幕截图和视频录制软件&#xff0c;它可以帮助用户快速捕捉屏幕上的任何内容&#xff0c;并将其编辑、标注和共享。 Snagit 2023 软件特点 多种截图模式&#xff1a;支持全屏截图、窗口截图、区域截图、延时截图等多种截图模式&#xff0c;满足不同用户…

机器学习笔记 - 深度学习中跳跃连接的直观解释

一、概述 如今人们利用深度学习做无数的应用。然而,为了理解在许多作品中看到的大量设计选择(例如跳过连接),了解一点反向传播机制至关重要。 如果你在 2014 年尝试训练神经网络,你肯定会观察到所谓的梯度消失问题。简单来说:你在屏幕后面检查网络的训练过程,你看到的只…

STM32+2.9inch微雪墨水屏(电子纸)实现显示

本篇文章从硬件原理以及嵌入式编程等角度完整的介绍了墨水屏驱动过程&#xff0c;本例涉及的墨水屏为2.9inch e-Paper V2,它采用的是“微胶囊电泳显示”技术进行图像显示&#xff0c;其基本原理是悬浮在液体中的带电纳米粒子受到电场作用而产生迁移&#xff0c;从而改变显示屏各…

第63讲:MySQL存储过程变量传参的核心概念与案例

文章目录 1.存储过程传参2.存储过程传参的语法结构3.存储过程传参经典案例3.1.IN类型的传参3.2.IN和OUT同时使用的传参3.3.INOUT类型的传参 1.存储过程传参 在创建存储过程时&#xff0c;存储过程名称后面的括号里是可以传入一些参数的&#xff0c;例如传入一个变量&#xff0…

OpenCV+QT实现的数字图像处理算法合集

源码下载地址&#xff1a; 基于OpenCV和QT的图像处理源码 图像预处理 灰度处理 灰度直方图 灰度均衡 梯度锐化 Laplace锐化 边缘检测 Roberts Sobel Laplace Prewitt canny Krisch 噪声 椒盐噪声 高斯噪声 滤波 均值滤波 中值滤波 双边滤波 形态学滤波 高斯滤波 图像变…

CMMI V2.0能力域

1、概念 能力域是一组相关的PA&#xff0c;可以提高组织或项目的技能和活动的性能。能力域视图是CMMI模型的一个子集&#xff0c;描述了构成特定能力域的一组预定义PA。能力域是一种视图。如下面规划和管理工作能力域视图&#xff1a; 2、类别 类别是相关能力域的逻辑组或视图…

UnitTest框架的使用

文章目录 一、UnitTest框架是什么&#xff1f;二、UnitTest核心要素三、TestCase四、TestSuite & TestRunner 一、UnitTest框架是什么&#xff1f; UnitTest框架是python自带的一个单元测试框架&#xff0c;主要用它来做单元测试&#xff0c;它有以下特点&#xff1a; 能…

UE4 UltraDynamicSky 天气与水体交互

最上面的Lerp的A通道为之前的水面效果&#xff0c;B是做的冰面效果 用Dynamic_Landscape_Weather_Effects的BaseColor的R通道四舍五入作为Lerp的Alpha值 使用一张贴图&#xff0c;乘以RadialGradientExponential对材质边缘做弱化&#xff0c;RadialGradientExponential的Raid…

SpringBoot项目访问后端页面404

检查项目的路径和mapper映射路径没问题后&#xff0c;发现本级pom文件没有加入web启动模块的pom文件中 maven做项目控制时&#xff0c;要注意将maven模块加入到web启动模块中

YOLOv8改进实战 | 更换主干网络Backbone(四)之轻量化模型MobileNetV3

前言 轻量化网络设计是一种针对移动设备等资源受限环境的深度学习模型设计方法。下面是一些常见的轻量化网络设计方法: 网络剪枝:移除神经网络中冗余的连接和参数,以达到模型压缩和加速的目的。分组卷积:将卷积操作分解为若干个较小的卷积操作,并将它们分别作用于输入的不…

Linux tmux使用总结

文章目录 1 tmux介绍2 tmux概念会话Sessions、窗口Windows、面板Panesstatus line中字段含义 3 Sessions会话管理新建会话断开当前会话进入之前的会话关闭会话查看所有的会话 4 tmux快捷指令系统指令窗口&#xff08;Windows&#xff09;指令面板&#xff08;Panes&#xff09;…

【C++进阶(九)】C++多态深度剖析

&#x1f493;博主CSDN主页:杭电码农-NEO&#x1f493;   ⏩专栏分类:C从入门到精通⏪   &#x1f69a;代码仓库:NEO的学习日记&#x1f69a;   &#x1f339;关注我&#x1faf5;带你学习C   &#x1f51d;&#x1f51d; 多态 1. 前言2. 多态的概念以及定义3. 多态的实…

java 企业工程管理系统软件源码 自主研发 工程行业适用

工程项目管理软件&#xff08;工程项目管理系统&#xff09;对建设工程项目管理组织建设、项目策划决策、规划设计、施工建设到竣工交付、总结评估、运维运营&#xff0c;全过程、全方位的对项目进行综合管理 工程项目各模块及其功能点清单 一、系统管理 1、数据字典&am…

英语——分享篇——每日200词——3001-3200

3001——ascertain——[ˌsəteɪn]——vt.查明&#xff0c;弄清——ascertain——a苹果(编码)s美女(编码)certain确定(熟词)——吃苹果的美女确定已查明此事——It can be difficult to ascertain the facts. ——可能难以查明事实真相。 3002——disrupt——[dɪsrʌpt]——…

spring6-国际化:i18n | 数据校验:Validation

文章目录 1、国际化&#xff1a;i18n1.1、i18n概述1.2、Java国际化1.3、Spring6国际化1.3.1、MessageSource接口1.3.2、使用Spring6国际化 2、数据校验&#xff1a;Validation2.1、Spring Validation概述2.2、实验一&#xff1a;通过Validator接口实现2.3、实验二&#xff1a;B…

Python 安装CSF(布料模拟滤波)的环境配置

一、环境配置 1.1 下载源码: Github下载CSF库源码 1.2 解压文件如下: 二、安装CSF库 2.1在解压文件中找到python文件夹所在目录 2.2 输入cmd并回车,来打开终端窗口 2.3激活虚拟环境 通过: activate +你的虚拟环境名称。来激活安装CSF库的虚拟环境。【不执行此

VM16Pro的Win10虚拟机安装Linux子系统Kali

VM16Pro的Win10虚拟机安装Linux子系统Kali 一、启用Windows功能二、配置WSL三、安装Kali四、安装kali基本工具包五、图形化六、适用的报错七、其他问题参考 一、启用Windows功能 启用后需重启二、配置WSL wsl --update #管理员启动Powershell执行&#xff0c;完成后将下面…

GitLab-访问返回403 forbidden问题处理

访问gitlab时报错forbidden 一般访问量大&#xff0c;密码错误频率高的时候&#xff0c;gitlab防爆机制启动了&#xff0c;对IP做了封禁&#xff0c;导致某些IP访问的是否返回 403 forbidden 1. 查看被封的IP /opt/gitlab/embedded/bin/redis-cli -s /var/opt/gitlab/redis/red…

vant组件是使用?

首先 在vue项目中使用的时候 要先下载组件 使用npm安装 # Vue 3 项目&#xff0c;安装最新版 Vant npm i vant# Vue 2 项目&#xff0c;安装 Vant 2 npm i vantlatest-v2 使用yarn安装或pnpm # 通过 yarn 安装 yarn add vant# 通过 pnpm 安装 pnpm add vant 在框架中引入即…

数据要素安全流通:挑战与解决方案

文章目录 数据要素安全流通&#xff1a;挑战与解决方案一、引言二、数据要素安全流通的挑战数据泄露风险数据隐私保护数据跨境流动监管 三、解决方案加强数据安全防护措施实施数据隐私保护技术建立合规的数据跨境流动机制 四、数据安全流通的未来趋势01 数据价值与产业崛起02 多…