Skip to content

Instantly share code, notes, and snippets.

@capotej
Created July 20, 2009 20:50
Show Gist options
  • Save capotej/150902 to your computer and use it in GitHub Desktop.
Save capotej/150902 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'amatch'
require 'digest/sha1'
#data structs
REF_SHA = Digest::SHA1.hexdigest('I would much rather hear more about your whittling project')
DICT = File.read('mydict.txt').map { |x| x.chomp }
ALPHA = (('A'..'Z').to_a << ('a'..'z').to_a).flatten
HAM = Amatch::Hamming.new(REF_SHA)
def produce_sentence
(1..rand(28)).map { DICT[rand(1000)] }.join(' ')
end
def permute(str)
str.split('').map do |a|
decision = rand(2)
if decision == 1
a.upcase
else
a.downcase
end
end.join('') + salt.to_s
end
def salt
(1..rand(5)).map { ALPHA[rand(52)] }
end
File.open(Time.now.to_i.to_s + '.txt', 'w') do |f|
loop do
string = permute(produce_sentence)
sha = Digest::SHA1.hexdigest(permute(produce_sentence))
distance = HAM.match(sha)
if distance < 29
f.puts "#{distance}::#{string}"
f.flush
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment