Skip to content

Instantly share code, notes, and snippets.

View raullenchai's full-sized avatar
🎯
Focusing

Raullen Chai raullenchai

🎯
Focusing
View GitHub Profile
@raullenchai
raullenchai / w1q1.py
Created March 27, 2012 18:45
Solve Week 1 Question 1 in Stanford Crypto Course
CT = ( '315c4eeaa8b5f8aaf9174145bf43e1784b8fa00dc71d885a804e5ee9fa40b16349c146fb778cdf2d3aff021dfff5b403b510d0d0455468aeb98622b137dae857553ccd8883a7bc37520e06e515d22c954eba5025b8cc57ee59418ce7dc6bc41556bdb36bbca3e8774301fbcaa3b83b220809560987815f65286764703de0f3d524400a19b159610b11ef3e','234c02ecbbfbafa3ed18510abd11fa724fcda2018a1a8342cf064bbde548b12b07df44ba7191d9606ef4081ffde5ad46a5069d9f7f543bedb9c861bf29c7e205132eda9382b0bc2c5c4b45f919cf3a9f1cb74151f6d551f4480c82b2cb24cc5b028aa76eb7b4ab24171ab3cdadb8356f', '32510ba9a7b2bba9b8005d43a304b5714cc0bb0c8a34884dd91304b8ad40b62b07df44ba6e9d8a2368e51d04e0e7b207b70b9b8261112bacb6c866a232dfe257527dc29398f5f3251a0d47e503c66e935de81230b59b7afb5f41afa8d661cb', '32510ba9aab2a8a4fd06414fb517b5605cc0aa0dc91a8908c2064ba8ad5ea06a029056f47a8ad3306ef5021eafe1ac01a81197847a5c68a1b78769a37bc8f4575432c198ccb4ef63590256e305cd3a9544ee4160ead45aef520489e7da7d835402bca670bda8eb775200b8dabbba246b130f040d8ec6447e2c767f3d30ed81ea2e4c1404e1315a1010e7229be6636aaa', '3f561ba9adb4b6ebec544
@raullenchai
raullenchai / w1q2.py
Created March 27, 2012 18:46
Solve Week 1 Question 2 in Stanford Crypto Course
CT = (210205973, 22795300, 58776750, 121262470, 264731963, 140842553, 242590528, 195244728, 86752752)
P = 295075153L # about 2^28
class WeakPrng(object):
def __init__(self, p, x, y): # generate seed with 56 bits of entropy
self.p = p
self.x = x
self.y = y
def next(self):
@raullenchai
raullenchai / TidyBib.py
Created April 12, 2012 17:37
Remove Unreferenced Bibitems in Latex/Tex File
"""
Remove Unreferenced Bibitems in Latex/Tex File
Author: Raullen Chai
Date: 2012-04-12
"""
from random import *
import re
"""
@raullenchai
raullenchai / try.py
Created April 13, 2012 01:36
Qualification Round Africa 2010 (B)
"""
http://code.google.com/codejam/contest/351101/dashboard#s=p1
"""
__author__ = 'Raullen'
f = open('B-large-practice.in','r')
N = int(f.readline())
@raullenchai
raullenchai / try.py
Created April 13, 2012 02:16
Qualification Round Africa 2010 (C)
"""
http://code.google.com/codejam/contest/351101/dashboard#s=p2
"""
__author__ = 'Raullen'
codebook = { 'A': '2', 'B': '22', 'C': '222',
'D': '3', 'E': '33', 'F': '333',
'G': '4', 'H': '44', 'I': '444',
'J': '5', 'K': '55', 'L': '555',
@raullenchai
raullenchai / try.py
Created April 13, 2012 02:53
Qualification Round Africa 2010 (A)
"""
http://code.google.com/codejam/contest/351101/dashboard#s=p0
"""
__author__ = 'Raullen'
f = open('C-small-practice.in','r')
N = int(f.readline())
g = open('res.out','w')
res = list()
@raullenchai
raullenchai / katan.py
Created May 11, 2012 22:09
Python Implementation of the KATAN Family of Block Ciphers
__author__ = 'Raullen'
IR = (
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1,
0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0,
1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0,
0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1,
1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1,
0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0,
@raullenchai
raullenchai / katan.c
Created May 16, 2012 17:40
The KATAN/KTANTAN Family of Block Ciphers
#include <stdio.h>
/*
Fork From http://www.cs.technion.ac.il/~orrd/KATAN/katan.c
Reference BITSLICED implementations of:
KATAN32, KATAN48, KATAN64, KTANTAN32, KTANTAN48 and KTANTAN64.
Each of the 64 slices corresponds to a distinct instance.
To work with a single instance, use values in {0,1}
@raullenchai
raullenchai / pyAES.py
Created June 12, 2012 20:52
Python AES implementation (pasted from http://brandon.sternefamily.net/files/pyAES.txt)
#!/usr/bin/python2.5
# Copyright (c) 2007 Brandon Sterne
# Licensed under the MIT license.
# http://brandon.sternefamily.net/files/mit-license.txt
# Python AES implementation
import sys, hashlib, string, getpass
from copy import copy
from random import randint
@raullenchai
raullenchai / Inv.py
Created July 2, 2012 17:14
Compute the Inverse of a Permutation in F_2^n
import math
def isPerm(x):
if math.log(len(x), 2)% 1 != 0:
return False
for i in range(len(x)):
try:
x.index(i)
except ValueError: