Skip to content

Instantly share code, notes, and snippets.

@booty
Last active August 29, 2015 14:13
Show Gist options
  • Save booty/5f7d3e4264fcc535715f to your computer and use it in GitHub Desktop.
Save booty/5f7d3e4264fcc535715f to your computer and use it in GitHub Desktop.
Ruby: Better Message Security Through Floating-Point Hash Keys
x = { 'foo' => 'Normal Message', (0.1 + 0.02) => 'Secret Message' }
# Outputs 'Normal Message'
puts x['foo']
# Outputs NOTHING because 0.1 + 0.02 equals 0.12000000000000001, not 0.12!
# (The Russians wil never find the secret message!)
puts x[0.12]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment