格两例12345

2024-03-05 02:04
文章标签 两例 12345

本文主要是介绍格两例12345,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

osu/Lucky Roll gaming

周末osu有道题:lcg已知低位

def lcg(s, a, b, p):return (a * s + b) % pp = getPrime(floor(72.7))
a = randrange(0, p)
b = randrange(0, p)
seed = randrange(0, p)
print(f"{p = }")
print(f"{a = }")
print(f"{b = }")def get_roll():global seedseed = lcg(seed, a, b, p)return seed % 100out = []
for _ in range(floor(72.7)):out.append(get_roll())
print(f"{out = }")flag = open("flag.txt", "rb").read()
key = bytes([get_roll() for _ in range(16)])
iv = bytes([get_roll() for _ in range(16)])
cipher = AES.new(key, AES.MODE_CBC, iv)
print(cipher.encrypt(pad(flag, 16)).hex())

题目很短,先给出lcg的参数,然后输出72个seed%100的值,后边是AES不是重点。

从网上搜到一例是给出高位的:crypto-babyLCG(NPUCTF2020)_lcg已知低位-CSDN博客 

名字上是低位实际上是高位。共128位已知高64位。转出来式子:

l_{2} = al_{1}+(ah_{1}+b-h_{2}) 从式子上看泄露部分跟高位还是低位无关,所以构造格是完全相同的。

\begin{vmatrix} m & 0 & 0\\ A & 1 & 0\\ B & 0 & m/100 \end{vmatrix} 

m = 4420073644184861649599
a = 1144993629389611207194
b = 3504184699413397958941
l = [0,39, 47, 95, 1, 77, 89, 77, 70, 99, 23, 44, 38, 87, 34, 99, 42, 10, 67, 24, 3, 2, 80, 26, 87, 91, 86, 1, 71, 59, 97, 69, 31, 17, 91, 73, 78, 43, 18, 15, 46, 22, 68, 98, 60, 98, 17, 53, 13, 6, 13, 19, 50, 73, 44, 7, 44, 3, 5, 80, 26, 10, 55, 27, 47, 72, 80, 53, 2, 40, 64, 55, 6]
enc = '34daaa9f7773d7ea4d5f96ef3dab1bbf5584ecec9f0542bbee0c92130721d925f40b175e50587196874e14332460257b'A = [1]
B = [0]
for i in range(1, len(l)-1):A.append(a*A[i-1] % m)B.append((a*B[i-1]+(a*l[i]+b-l[i+1])*inverse_mod(100,m)) % m)
A = A[1:]
B = B[1:]
dim = len(l)
M = matrix(ZZ, dim, dim)
for i in range(dim-2):M[i, i] = mM[-2, i] = A[i]M[-1, i] = B[i]M[i, -2] = M[i, -1] = 0
M[-2,-2] =  1
M[-1,-1] = m//100  #高位的规模 格与高低位无关,但需要未知部分明显小于模ll = M.LLL()[0]
l1 = ll[-2]
h1 = l[1]
s1 = l1*100+h1
#for s1=a*seed+b%m
seed = ((s1-b)*inverse_mod(a,m))%m
print(seed)def get_roll():global seedseed = (seed*a+b)%mreturn int(seed % 100)seed = 728664259414514712557
out = []
for _ in range(floor(72.7)):out.append(get_roll())key = bytes([get_roll() for _ in range(16)])
iv = bytes([get_roll() for _ in range(16)])from Crypto.Cipher import AES
cipher = AES.new(key, AES.MODE_CBC, iv)
print(cipher.decrypt(bytes.fromhex(enc)))
#osu{w0uld_y0u_l1k3_f1r5t_0r_53c0nd_p1ck}

第2题来自gcc ctf 

GCC/TooManyLeaks

题目也很短给出g,A=2^a,B=2^b,c,AC=2^(a+c),s = B^a,s2=AC^b 其中s,s2仅给出高257位

s_{2} = AC^{b}=2^{ab+bc}=2^{ab}*2^{bc}=s_{1}*B^c

再通过r1,r2分别是s1,s2的高位得到

-x+y*BC+r2-r1*BC = 0 (mod p)

从rec师傅那问到构造方法(前边自己想的几个都没成功)

\begin{vmatrix} 1 & 0 & BC\\ 0 & 2^{255} & R\\ 0 & 0 & p \end{vmatrix}

用自制的数据验证得到的结果:第1个是-x但后边并不是y,y通过计算得到

p=12659765344651740648724763467724826993725936263366951091039118416195292099370631377712042960634433459603684366298668316118798753725083109726606307230709481
A=3301451331273103822833339817189898484477574460332521541023442766617163003861277567173209945681794302860954824946103841799431004692332025577336344394695314
B=4585794959794770660643739179463936175470737153250504109915159478661133411133496952267060123069524419032124459912888910847574766484421490926652243218962165
r1=2568748433813321161874639775621008976218176085243148442053880160521563872123950485879781803171876295709491228751046125319137014580919198982132588104122368
c=13305825506775525477695274133373660177357107668926266252207560823721404224069651345842091298405541700114875323083835571095924844005731356668708175418706451
AC=7245241643057289361660908682282370311759108862519890618466911853745311287850476739612486696335989486506224784314474292337315512082870292214611222140900864
r2=3829741721947473719324421527352078984331611168371079834096760630101921404398331513243772077101441758022492336098369985623504441570880895898971858238701568
ciphertext = bytes.fromhex('89c372210be2a7b313366206f7426f941157009493d00fcb18b467250139413b6ea1ada6302e1916b6c02a6f935f4ed4')
iv = bytes.fromhex('c7d192fb72b529acf7b57d488c182466')'''
A = 2^a ,B = 2^b ,AC = 2^(a+c)
s = B^a = 2^(ab) => r1+x = 2^(ab)
s2 = AC^b = 2^(ab+bc) = 2^ab * 2^bc = s * B^c => r2 + y = (r1+x)*BC = r1*BC + x*BC
-x + y*BC+ r1*BC - r2 = 0 mod p 
|1 0 BC|
|0 1 R |.LLL() = |y k x|
|0 0 p |
'''
BC = pow(B,c,p)
R = int((r1*BC-r2)%p)
M = matrix(ZZ,[[1,0,BC],[0,2^255,R],[0,0,p]])
L = M.LLL()
'''
[ -25633356745769628425188974048965624683829363674340702376652630056616274263520                                                                               0   25192355301191283908458965869175850121091834483889075955116860140524780856947]
[  16398029187545116410379158779174289772216017281301637621417139570711691284296   57896044618658097711785492504343953926634992332820282019728792003956564819968   41036197941114149842214882116707031982582245609637689544867914273576525805038]
[-149510885595142246734642323500819848441581984553636254311696365107836707555515  173688133855974293135356477513031861779904976998460846059186376011869694459904 -175483554550299102224589434426378557989582203738521393133765379465260896275103]
'''
for v in L:x,k,y = vy.nbits()x.nbits()hex(x)hex(y)x = 25633356745769628425188974048965624683829363674340702376652630056616274263520
#y = BC*(r1+x)%p-r2
y = 41036197941114149842214882116707031982582245609637689544867914273576525805038
#0x5ab9aa3a0a42183deb14e8725ef711b906ecc058e8be025b04d2d5322104b5ee
s = r1+x 
#0x310bc7e26b23c79469a5c1eb7b210f527af22ba0d17726051cd95216d6cdfd862440f4a33747fa708f7b878e6b882f164a2e7cf72cc2b67754c416a3fc6c4f48import hashlib
from Crypto.Cipher import AESsha1 = hashlib.sha1()
sha1.update(str(s).encode('ascii'))
key = sha1.digest()[:16]cipher = AES.new(key, AES.MODE_CBC, iv)
flag = cipher.decrypt(ciphertext)
#b'GCC{D1ff13_H3llm4n_L34k_15_FUn!!}\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f\x0f'

这篇关于格两例12345的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/774978

相关文章

两例Eclipse不能启动Tomcat服务的处理过程

今天接到两次关于Eclipse不能启动Tomcat服务的求助,和大家分享一下第一例:    在Eclipse中启动Tomcat服务时提示8888等端口被占用,  问题是突然出现的,之前还能正常启动, 怀疑是已经启动了一个Tomcat服务, 但是重启Eclipse错误依旧于是先在命令行用netstat -a -b 来显示应用程序占用端口的情况,发现这几个端口都是被javaw.exe这个程序占用, 这

java 读取文件 两例

1          采用InputStream is = new FileInputStream(File filePath);等输入流的 形式,读取文件并存放在StringBuffer中。   import  java.io.BufferedReader; import  java.io.File; import  java.io.FileInputStream; import

方法论,企业的数字化转型12345

文/张涵诚 用区块链从新定义生产关系,用云量、用数量、移动指数、物联网指数、数据的应用和开放能力重新定义生产力,实现现代企业的五化管理工作移动化、数据产品化、分析可视化、管理云化、业务融合化。笔者认为这就是数字化转型的要做的事情,总结起来就 是:一个平台,两个核心技能,三个阶段,四个战略内容,五化建设。 一个平台是指: l   一个企业的云计算平台,有

两例JavaScript 获取当前系统日期和时间

两例JavaScript 获取当前系统日期和时间 QUOTE: <script language="JavaScript"> //定义一个tick函数,以获取系统的时间 function tick() { var year,month,day,hours,minutes,seconds,ap; var intYear,intMonth,intDay,intHours,intMinutes,in

char str1[11] = 12345\06789; 引发的深刻教训---原来'\067'与'7'是相等的

一直以来, 我总是以为char str1[11] = "12345\06789";和char str2[11] = {'1', '2', '3', '4', '5', '\0', '6', '7', '8', '9', '\0'};是完全等价的。直到今天调试一个程序, 我才发现, 他们原来是不等价的, 我被这个问题蒙在鼓里, 看来有必要深入看看。         我一直苦苦思索原

两例MFC程序flag获取

先上图: MFC应用程序破解需要找到某个按钮对应的消息处理函数(不能单纯理解成Win32项目,去找自定义的消息处理函数),可以在关键函数处下断点,比如:GetDlgItem( )  GetDlgText( )  SetDlgText( )  GetWindowText( )  SetWindowText( )  GetDlgItemText( ) SetDlgItemText( ) Regi

两例由金手指氧化或插槽接触不良引起的硬件故障,0x00000221蓝屏与显示器不亮解决办法

两台十年前的电脑,华硕M5A78L的板子,但是断断续续更换了新的cpu、内存、显卡及固态硬盘(饥饿鲨固态真的好用,可惜现在倒闭了),跑永劫无间高画质依旧很顺滑。比起我一朋友花了大几千新配台电脑才能跑永劫无间算是省了不少钱。 随着夏天的来临,感觉CPU温度一年比一年高,一般是因为cpu与散热器间涂抹的散热硅脂失效了,散热硅胶是三年有效期,我这有10年没换过了,电脑速度也很受影响。 第一台电脑换硅