This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sage.all import * | |
from itertools import product | |
def frombin(v): | |
return int("".join(map(str, v)), 2 ) | |
def l33tize(s, eight=False): | |
ms = GL(8 if eight else 6, GF(2)) | |
while 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from binascii import crc32 | |
def lcg_step(): | |
global lcg | |
lcg = (0x5851F42D4C957F2D * lcg + 0x14057B7EF767814F) % 2**64 | |
return lcg | |
def extract(val): | |
res = 32 + val - 95 * (( | |
((val - (0x58ED2308158ED231 * val >> 64)) >> 1) + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Print a Flag. | |
* @author Daniel Bleichenbacher | |
*/ | |
package blt; | |
import java.math.BigInteger; | |
import java.security.MessageDigest; | |
import java.security.SecureRandom; | |
import java.security.GeneralSecurityException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import signal, random | |
import sys | |
class LinearCongruentialGenerator: | |
def __init__(self, a, b, nbits): | |
self.a = a | |
self.b = b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use permutation::Permutation; | |
use cube::Cube; | |
use crypto::blake2b::Blake2b; | |
#[derive(Copy, Clone, Eq, PartialEq, Hash)] | |
pub struct SecretKey { | |
pub a: u64, | |
pub b: u64, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
CRC is affine. | |
CRC(x) = L(x) + C, where L is linear. | |
We want CRC(x) = L(x) + C = x. | |
Write as L(x)+x = C. | |
Solve matrix equation. | |
''' | |
from sage.all import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate arrayref; | |
extern crate crypto; | |
use crypto::aead::AeadDecryptor; | |
use crypto::chacha20poly1305::ChaCha20Poly1305; | |
use std::env; | |
use std::fs::File; | |
use std::io::{Read, Write}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding:utf-8 -*- | |
""" | |
In this challenge we have a Paillier cryptosystem. | |
We are given a decryption oracle, which leaks only one bit in the middle of the plaintext. | |
Due to homomorphic properties of the Paillier cryptosystem, we can recover the full decryption using such an oracle. | |
1. First, we recover the lower half of the message bit-by-bit. | |
This can be done by manipulating and observing the carry bit going through the pinhole, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'securerandom' | |
## Parameters | |
P = 115792089237316195423570985008687907853269984665640564039457584007913129639747 | |
N = 100 | |
K = 25 | |
L = 38 # The number of liars | |
def apply_polynomial(coeffs, x) | |
r = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Attacking McEliece with Generalized Reed-Solomon codes (GRS), method by Sidelnikov & Shestakov. | |
The task is almost the same as The Russian Attack from Sharif CTF: | |
http://ctf.sharif.edu/blog/Write-Ups/SharifCTF-6/Crypto/08.%20The%20Russian%20Attack%20(500%20+%20300%20pts)/ | |
The only change is the field changed from GF(p) to GF(2^8). | |
Here is Sage analogue of the GAP script, because finally Sage supports GRS decoding. | |
''' |