Tuesday, June 21, 2011

sha2 encryption in ruby

require 'digest/sha2'; hash = Digest::SHA2.new; hash << "text to encrypt"; hash.to_s

<< basically adds the parameter to the object. 'f' << 'oo' # -> 'foo' and [1] << 2 # -> [1,2]

but it might be a left shift also ;) 2 << 3 # -> 16
it shifts the bit representation of a number. 0b001 << 1 # -> 0b010
with 0b001 == 1 and 0b010 == 2