Skip to content

Instantly share code, notes, and snippets.

@skiz
Created July 14, 2009 18:57
Show Gist options
  • Save skiz/147113 to your computer and use it in GitHub Desktop.
Save skiz/147113 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'digest/sha1'
require 'rubygems'
require 'amatch'
require 'bio'
challenge_phrase = File.read('challenge.txt')
challenge_sha1 = Digest::SHA1.hexdigest(challenge_phrase)
words = File.read('dict.txt').split("\n").uniq
test_phrase = words.sort{rand <=> 0.5}[3..rand(10)+5].join(' ')
threshold = 29
cycles = 1000000
cycles.times do |x|
randomness = ('a'..'z').sort{rand <=> 0.5}[0..5].join
5.times do |r|
phrase = test_phrase + randomness[0..r]
test_phrase_sha1 = Digest::SHA1.hexdigest(phrase)
m = Amatch::Hamming.new(test_phrase_sha1)
offset = m.match(challenge_sha1).to_s
if offset.to_i <= threshold
puts "'#{phrase}' => #{offset}"
end
end
puts '.' if x % 1000 == 0
end
@skiz
Copy link
Author

skiz commented May 7, 2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment