Skip to content

Instantly share code, notes, and snippets.

@piotrplaneta
Created November 14, 2012 16:12
Show Gist options
  • Select an option

  • Save piotrplaneta/4073031 to your computer and use it in GitHub Desktop.

Select an option

Save piotrplaneta/4073031 to your computer and use it in GitHub Desktop.
require 'digest/sha1'
bob_texts_c = []
mallory_texts_c = []
bob_texts = {}
mallory_texts = {}
bob_text = 'Wyplacic Bobowi 100 zlotych.'
mallory_text = 'Wyplacic Mallory 100 zlotych.'
letters = ('a'..'z').to_a
puts letters.combination(2).to_a.length
letters.combination(2).each_with_index do |word, index|
bob_texts_c.push(Digest::SHA1.hexdigest(bob_text + word.join)[-4, 4])
bob_texts[Digest::SHA1.hexdigest(bob_text + word.join)[-4, 4]] = (bob_text + word.join)
mallory_texts_c.push(Digest::SHA1.hexdigest(mallory_text + word.join)[-4, 4])
mallory_texts[Digest::SHA1.hexdigest(mallory_text + word.join)[-4, 4]] = (mallory_text + word.join)
end
(bob_texts_c & mallory_texts_c).each do |text|
puts bob_texts[text] + " = " + mallory_texts[text]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment