class Lingo::Database::Crypter

Crypter ermöglicht die Ver- und Entschlüsselung von Wörterbüchern

Constants

HEX_CHARS

Public Instance Methods

decode(key, val) click to toggle source
# 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
digest(key) click to toggle source
# File lib/lingo/database/crypter.rb, line 38
def digest(key)
  Digest::SHA1.hexdigest(key)
end
encode(key, val) click to toggle source
# 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

Private Instance Methods

crypt(k, v) click to toggle source
# 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