Skip to content

Instantly share code, notes, and snippets.

@rohit89
rohit89 / miner.c
Last active August 29, 2015 13:56
Generate git sha1 commit hash collision (used for Stripe CTF 3.0 level1 - gitcoin miner)
#include<stdio.h>
#include<openssl/sha.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
static void compute_stream_hash(char *a, char *b, char *c)
{
unsigned char sha1[20];
unsigned char hash[(20 * 2) + 1];
@rohit89
rohit89 / gist:1799191
Created February 11, 2012 12:25
Embedly Challenge #3
def harmonic_sum n
(1..n).each.inject(0) {|sum, i| sum += (1.0 / i)}
end
total_words = 2520 * harmonic_sum(900)
half = total_words / 2
sum = 0
(1..900).each do |i|
sum += 1.0 / i
@rohit89
rohit89 / gist:1799181
Created February 11, 2012 12:22
Embedly Challenge #2
require 'rubygems'
require 'hpricot'
require 'net/http'
def standard_deviation arr
mean = arr.each.inject(0) {|sum, i| sum += i; sum} / arr.length.to_f
new_arr = arr.each.map{|i| (i - mean) ** 2}
(new_arr.each.inject(0) {|sum, i| sum += i; sum} / new_arr.length.to_f) ** 0.5
end
@rohit89
rohit89 / gist:1799173
Created February 11, 2012 12:20
Embedly Challenge #1
def fact n
return 1 if n == 0
n.downto(1).inject(1) {|res, i| res *= i; res}
end
def sum n
n.to_s.each_char.map{|ch| ch.to_i}.inject(0) {|sum, i| sum += i; sum}
end
(400..1000).each do |i| # fact 400 has 869 digits...close to the 889 required