Skip to content

Instantly share code, notes, and snippets.

@simi
Created December 27, 2014 17:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simi/d041f95d2e6a6b8ea2f7 to your computer and use it in GitHub Desktop.
Save simi/d041f95d2e6a6b8ea2f7 to your computer and use it in GitHub Desktop.
require 'securerandom'
require 'set'
tokens = Set.new
i = ENV['I'].to_i
length = ENV['KEY_LENGTH'].to_i
i.times do |i|
hex = SecureRandom.hex(length)
raise "Collision found in iteration ##{i} with key length #{length}!" if tokens.include?(hex)
tokens << hex
end
print "No collision for #{i} iterations with key length #{length}.\n"
@simi
Copy link
Author

simi commented Dec 27, 2014

usage: I=10_000_000 KEY_LENGTH=24 ruby collision.rb

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