Skip to content

Instantly share code, notes, and snippets.

View anthonyclays's full-sized avatar

Anthony Clays anthonyclays

  • Leuven, Belgium
View GitHub Profile
#!/usr/bin/env perl
for (my $N=<>; $N; $N--){
$_ = "";
for (my $L=<>; $L; $L--) {
$_ .= <>;
}
for (my $L=<>; $L; $L--) {
my ($n, $r) = split(' ', <>);
s/($r( |$){$n}/\1/gm;
#!/usr/bin/env perl
<>;
foreach(<>){
s/(ij|[aeiou]+)p\1/\1/ig;
print;
}
#!/usr/bin/env julia
using CRC
# crc computing function
const handler = crc(CRC_32)
# offsets of IDAT chunks (points to 'I' byte)
const offsets = [114,131197,262278,393361,524445,655526,786609,917691,1048775,1179858,1188429]
# correct crcs. No 0x0a in those so we can assume they're correct ;)
const crcs = [0xf55a745d, 0x06e15ebf, 0xa0bdc18a, 0xadefb326, 0x09c557f7,
@anthonyclays
anthonyclays / curious.jl
Last active August 29, 2015 14:19
Curious solution
#!/usr/bin/env julia
# Adapted from https://github.com/pablocelayes/rsa-wiener-attack
using ContinuedFractions # Note: this needs my fork of ContinuedFractions.jl
# fast perfect square test (from project euler tools)
# returns -1 if n is not a perfect square
function perfect_square(n::Integer)
h = n & 0xF # last four bits
@anthonyclays
anthonyclays / break_caesar.jl
Last active August 29, 2015 14:20
Fully automated caesar rotation decryption using a 2D language entropy table
#!/usr/bin/env julia
const ENTROPY_MAP_2D = open("entropy.csv") do f
readdlm(f, ',')
end
# Returns index 1:26 for a-z, 27 for space
function get_index_for(ch)
if 'a' <= ch <= 'z'
return int(ch - 96)
@anthonyclays
anthonyclays / typesort.jl
Last active August 29, 2015 14:22
Typelevel quicksort (and integer arithmetic) in Julia
#!/usr/bin/env julia
# Peano arithmetic (https://en.wikipedia.org/wiki/Peano_axioms)
abstract Natural <: Integer
immutable Zero <: Natural end
immutable Successor{P<:Natural} <: Natural end
# Define a total order relation
<(::Type{Zero}, ::Type{Zero}) = false
<{P<:Natural}(::Type{Zero}, ::Type{Successor{P}}) = true
@anthonyclays
anthonyclays / generated_llvm
Last active August 29, 2015 14:27
LLVM wizardry
julia> code_llvm(g, (Int,))
define i64 @julia_g_20191(i64) {
top:
%1 = icmp sgt i64 %0, 0, !dbg !8
br i1 %1, label %L.preheader, label %L3, !dbg !8
L.preheader: ; preds = %top
%2 = add i64 %0, -1, !dbg !8
%3 = zext i64 %2 to i65
@anthonyclays
anthonyclays / sr830_repl.py
Created September 11, 2015 13:27
SR830 repl.
#!/usr/bin/env python
# encoding: utf-8
"""
Usage:
rlwrap ./srs_test.py
"""
import os
@anthonyclays
anthonyclays / partition.jl
Created September 11, 2015 15:23
Vector partitioning into n chunks
chunks(l::AbstractVector, n::Int) = let part_l = length(l) / n
[let start = floor(Int, (i-1)*part_l + 1), stop = floor(Int, i*part_l);
l[start:stop] end for i in 1:n]
end
@anthonyclays
anthonyclays / reveng_of_the_pancakes.pl
Last active April 10, 2016 08:38
Revenge of the pancakes
<>; # ignore first line of input
foreach(<>) {
chomp; # get rid of the newline
$t++; # increment case number (implicitly initialized to zero)
s/([+-])\1+/\1/g; # simplify stack of pancakes: consecutive similarly-facing pancakes are squashed together
s/\+$//; # if the last pancake is already facing the correct way: ignore it
$l=length; # get the height of the stack
print"Case #$t: $l\n" # print it
}