Skip to content

Instantly share code, notes, and snippets.

@Chrstm
Chrstm / noise.py
Last active Oct 25, 2020
D^3CTF 2019 Crypto - Noise
View noise.py
#!/usr/bin/env python3
from os import urandom
import signal
def getrandbits(bit):
return int.from_bytes(urandom(bit >> 3), "big")
def main():
@Chrstm
Chrstm / elasticsearch_array.py
Last active Apr 12, 2019
How to use array of general datatype in elasticsearch-dsl-py?
View elasticsearch_array.py
from elasticsearch_dsl import DocType, Index, Integer, Text, Q
from elasticsearch_dsl.connections import connections
import time
post_index = Index('test_post')
class PostDoc(DocType):
author_id = Integer() # List[Integer]
@Chrstm
Chrstm / algorithm_a.py
Created Mar 24, 2019
Fast Correlation Attacks - Algorithm A
View algorithm_a.py
BLOCK = 48
class LFSR:
def __init__(self, init, mask, length=BLOCK):
self.init = init
self.length = length
self.lengthmask = 2 ** length - 1
self.mask = mask & self.lengthmask
@Chrstm
Chrstm / mt_recover.py
Created Dec 2, 2018
recover python random state (Mersenne Twister)
View mt_recover.py
import random
class MT19937Recover:
"""Reverses the Mersenne Twister based on 624 observed outputs.
The internal state of a Mersenne Twister can be recovered by observing
624 generated outputs of it. However, if those are not directly
observed following a twist, another output is required to restore the
internal index.
See also https://en.wikipedia.org/wiki/Mersenne_Twister#Pseudocode .
@Chrstm
Chrstm / rsa_lsb_oracle_attack.py
Last active Aug 18, 2019
RSA LSB Oracle Attack
View rsa_lsb_oracle_attack.py
def lsb_oracle_attack(n, e, c, lsb_oracle):
'''
RSA LSB Oracle Attack
:param lsb_oracle: lsb_oracle(x) == pow(x, d, n) % 2
:return: m or None if not found
'''
l, r, k2 = 0, 1, 1
while n * l // k2 + 1 < n * r // k2:
m = l + r
l <<= 1