Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View maojui's full-sized avatar
🌵

Maojui maojui

🌵
View GitHub Profile
@maojui
maojui / LEA.py
Created November 27, 2020 12:30
Implementation of Length extend attack (LEA)
# Copyright (C) 2014 by Stephen Bradshaw
#
# SHA1 and SHA2 generation routines from SlowSha https://code.google.com/p/slowsha/
# which is: Copyright (C) 2011 by Stefano Palazzo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@maojui
maojui / sha1_collision.py
Last active November 27, 2020 12:24
Make given two images become SHA-1 Collision.
#! coding:utf-8
import os
from PIL import Image
from hashlib import sha1
from Crypto.Util.number import long_to_bytes as n2s
def sha1_collision(image1,image2) :
'''
Usage: input two image, open in bytes or just a string path
@maojui
maojui / cube_root.sage
Last active November 27, 2020 01:46
Find nth_root on modulo p
def cube_root(c, q):
F = FiniteField(q)
R.<x> = PolynomialRing(F,'x')
while 1:
a = F.random_element()
b = F.random_element()
fx = x**3 - a*x**2 + b*x - c
fc = list(factor(fx))
if len(fc) <= 1:
root = pow(x, (q**2+q+1)//3, fx)
def partial_p(p0, kbits, n):
PR.<x> = PolynomialRing(Zmod(n))
nbits = n.nbits()
f = 2^kbits*x + p0
f = f.monic()
roots = f.small_roots(X=2^(nbits//2-kbits), beta=0.3) # find root < 2^(nbits//2-kbits) with factor >= n^0.3
if roots:
x0 = roots[0]
p = gcd(2^kbits*x0 + p0, n)
@maojui
maojui / known_p_lsb.sage
Created November 23, 2020 15:26
Factoring with Partial Information of prime
"Find P with only knowning 50% of LSB (least significant bit)"
def recover_msb(n, p, known_bits, debug=False) :
beta = 0.5
epsilon = beta^2/7
PR.<x> = PolynomialRing(Zmod(n))
f = x*(2^kbits) + p
f = f.monic()
x = f.small_roots(X=2^(pbits-kbits), beta=0.3)[0] # find root < 2^kbits with factor >= n^0.3
return x
@maojui
maojui / ntru_attack.sage
Created November 22, 2020 08:45
Attack on NTRU Cryptosystem with weak parameters.
# Script is from https://latticehacks.cr.yp.to/ntru.html
import math
import numpy as np
from sympy.abc import x
from sympy import ZZ, Poly
from Crypto.Util.number import long_to_bytes
n = 71
d = 3
@maojui
maojui / wiener_attack.py
Last active November 22, 2020 08:30
Wiener Attack
import sys
from sympy.solvers import solve
from sympy import Symbol
# This is comes from https://github.com/sourcekris/RsaCtfTool/blob/master/wiener_attack.py
# A reimplementation of pablocelayes rsa-wiener-attack
# https://github.com/pablocelayes/rsa-wiener-attack/
class WienerAttack(object):
@maojui
maojui / boneh_durfee.sage
Created November 22, 2020 08:26
Boneh and Durfee Attack
#!/usr/bin/env sage
# This code is taken from https://github.com/mimoo/RSA-and-LLL-attacks
import time
############################################
# Config
##########################################
"""
contract DelegateCaller {
uint public n;
address public sender;
function delegatecallSetN(address _e, uint _n) {
_e.delegatecall(bytes4(keccak256("setN(uint256)")), _n); // D's storage is set, E is not modified
}
}
contract OuterContract {
pragma solidity ^0.4.18;
contract GuessNumber{
struct Player {
address addr;
uint number;
}
Player[2] private players;