crypto

Hardcore

模2同余方程组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from pwn import *

def foo(l):
return ''.join([str(i) for i in l])

import numpy as np
a=np.identity(256,dtype=np.int64)

r=remote('ctf.b01lers.com',9003)
r.sendline('1')
s=b''
r.recvuntil('answer.\n')
for i in range(256):
print(i,s)
r.sendline(foo(a[i]))
s+=r.recvline().strip()
print(s)
r.interactive()
1
2
3
4
5
from Crypto.Util.number import *

a=0b0110001001100011011101000110011001111011011001000110111101011111011110010110111101110101010111110110110001101001011010110110010101011111011010000110000101110010011001000110001101101111011100100110010101011111011000110110100001100001011011000111001101111101
print(long_to_bytes(a))
# bctf{do_you_like_hardcore_chals}

crypto

easy_real

爆破hash,xor密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from Crypto.Util.number import *
import hashlib
from pwn import *


h='37693cfc748049e45d87b8c7d8b9aacd'
n=4197356622576696564490569060686240088884187113566430134461945130770906825187894394672841467350797015940721560434743086405821584185286177962353341322088523
c=3298176862697175389935722420143867000970906723110625484802850810634814647827572034913391972640399446415991848730984820839735665233943600223288991148186397


for i in range(1,100):
if hashlib.md5(str(i).encode()).hexdigest()==h:
e=i

p = 64310413306776406422334034047152581900365687374336418863191177338901198608319
q=n//p

d=inverse(e,(p-1)*(q-1))
m=pow(c,d,n)
m=long_to_bytes(m)
l=len(m)
for i in range(1,10):
a=bytes([i]*l)
a=xor(a,m)
if b'flag' in a:
print(a)
阅读全文 »

ezRSA

方法1

p,q的900位以后的高位hb都是一样的,可以先求出来

\(p=hb+y\),那么\(q=hb+2^{900}-y+z\),z为300位的随机数,可以得到 \[ p+q=2hb+2^{900}+z,\ p-q=2y-2^{900}-z \] 因为\(n=pq\)\(p+q\)的高位(低300位未知)已知,可以由\(p-q=\sqrt{(p+q)^2-4n}\)求出\(p-q\)的近似值相应的y的近似值也能求出,再用coppersmith求出y的低位从而求出p

阅读全文 »

速查

LLL算法

\[ ||v_1|| ≤ ||v_2|| ≤ ... ≤ ||v_i|| ≤ 2^{ \frac{n(n−1)}{4(n+1−i)}}det(L)^{\frac{1}{n+1−i}}\\ ||v_1|| ≤ 2^{ \frac{n−1}{4}}det(L)^{\frac{1}{n}} \] #### Minkowski定理

格子L存在向量 \(v\) ,满足 \(||v||\le \sqrt{n}\ det(L)^\frac{1}{n}\)

CopperSmith算法

sage自带

1
2
3
4
n=10001
P.<x> = PolynomialRing(Zmod(n))
f=x^3 + 10*x^2 + 5000*x - 222
f.small_roots(X=10)

参数见 sage doc

多元coppersmith脚本

脚本参考 coppersmith 参数:

  • f 函数
  • bounds 各变量的上界X组成的元组tuple
  • m 模的幂
  • d variable shifts(多元时要手动设置为f的项的个数)
    阅读全文 »

d3factor

方法1

造格子 设\(\epsilon=d_2-d_1\),有 \(e_1e_2\epsilon +e_2-e_1\equiv0\ mod\ p^6\) 化为\(\epsilon+b=kp^6,\ b\equiv(e_1e_2)^{-1}(e_2-e_1)\ mod\ p^6\)\(M=N^{\frac{1}{2}}\)\(L=\begin{pmatrix}M&b\\\\ 0&N\end{pmatrix}\) \((pq\ -k)L=(pqM\ -pq\epsilon)\)

阅读全文 »

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment