class Cinch::Plugins::EnCinch::Encryption
Public Class Methods
new(key)
click to toggle source
# File lib/cinch/plugins/encinch/encryption.rb, line 60 def initialize(key) @blowfish = Crypt::Blowfish.new(key) end
Public Instance Methods
decrypt(data)
click to toggle source
# File lib/cinch/plugins/encinch/encryption.rb, line 78 def decrypt(data) data.sub!(/^\+OK\s+/, '') return nil if not data.length % 12 == 0 result = String.new num_block = (data.length / 12).to_i num_block.times do |n| block = Base64.decode( data[n*12..(n + 1)*12-1] ) result += @blowfish.decrypt_block(block) end result.gsub(/\0*$/, '') end
encrypt(data)
click to toggle source
# File lib/cinch/plugins/encinch/encryption.rb, line 64 def encrypt(data) data = pad(data, 8) result = String.new num_block = data.length / 8 num_block.times do |n| block = data[n * 8..(n + 1) * 8 - 1] enc = @blowfish.encrypt_block(block) result += Base64.encode(enc) end "+OK " << result end
Private Instance Methods
pad(data, n=8)
click to toggle source
# File lib/cinch/plugins/encinch/encryption.rb, line 96 def pad(data, n=8) pad_num = n - (data.length % n) pad_num.times { data += 0.chr } if pad_num > 0 and pad_num != n data end