Crypter ermöglicht die Ver- und Entschlüsselung von Wörterbüchern
# File lib/lingo/database/crypter.rb, line 48 def decode(key, val) crypt(key, val.each_byte.each_slice(2).with_object('') { |b, s| q, r = b.map { |i| HEX_CHARS.index(i.chr(ENC)) } s << q * 16 + r }) end
# File lib/lingo/database/crypter.rb, line 38 def digest(key) Digest::SHA1.hexdigest(key) end
# File lib/lingo/database/crypter.rb, line 42 def encode(key, val) [digest(key), crypt(key, val).each_byte.with_object('') { |b, s| b.divmod(16).each { |i| s << HEX_CHARS[i] } }] end
# File lib/lingo/database/crypter.rb, line 57 def crypt(k, v) c, y = '', k.codepoints.reverse_each.cycle v.each_codepoint { |x| c << (x ^ y.next).chr(ENC) } c end