class Cipher::VNCDES
Attributes
key[R]
Public Class Methods
new(key)
click to toggle source
# File lib/cipher/vncdes.rb, line 33 def initialize(key) @key = normalized(key[0..7]) self end
Public Instance Methods
encrypt(challenge)
click to toggle source
# File lib/cipher/vncdes.rb, line 38 def encrypt(challenge) chunks = [challenge.slice(0, 8), challenge.slice(8, 8)] cipher = OpenSSL::Cipher::DES.new(:ECB) cipher.encrypt cipher.key = self.key chunks.reduce('') { |a, e| cipher.reset; a << cipher.update(e) }.force_encoding('UTF-8') end
Private Instance Methods
normalized(key)
click to toggle source
# File lib/cipher/vncdes.rb, line 48 def normalized(key) rev = ->(n) { (0...8).reduce(0) { |a, e| a + 2**e * n[7 - e] } } inv = key.each_byte.map { |b| rev[b].chr }.join inv.ljust(8, "\x00") end