Top Level Namespace
Constant Summary collapse
- SALT_LENGTH =
30
- ALPHA =
('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
Instance Method Summary collapse
- #generate_salt ⇒ Object
- #hash_fn(str) ⇒ Object
- #salted_hash(str, salt) ⇒ Object
- #salty(str) ⇒ Object
- #salty_eq(unhashed, hashed) ⇒ Object
Instance Method Details
#generate_salt ⇒ Object
11 12 13 |
# File 'lib/salty.rb', line 11 def generate_salt (1..SALT_LENGTH).map{ALPHA.sample}.join end |
#hash_fn(str) ⇒ Object
6 7 8 9 |
# File 'lib/salty.rb', line 6 def hash_fn(str) sha512 = Digest::SHA2.new(512) sha512.hexdigest(str) end |
#salted_hash(str, salt) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/salty.rb', line 15 def salted_hash(str,salt) res = str 100.times do res = hash_fn(res+salt) end res end |
#salty(str) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/salty.rb', line 23 def salty(str) salt = generate_salt res = salted_hash(str,salt) n = str.length res[0...n] + salt + res[n..-1] end |
#salty_eq(unhashed, hashed) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/salty.rb', line 32 def salty_eq(unhashed,hashed) n = unhashed.length salt = hashed[n,SALT_LENGTH] myhashed = hashed[0...n] + hashed[n+SALT_LENGTH..-1] myhashed == salted_hash(unhashed,salt) end |