module Zip::TraditionalEncryption
Public Class Methods
new(password)
click to toggle source
# File lib/zip/crypto/traditional_encryption.rb, line 3 def initialize(password) @password = password reset_keys! end
Public Instance Methods
gp_flags()
click to toggle source
# File lib/zip/crypto/traditional_encryption.rb, line 12 def gp_flags 0x0001 | 0x0008 end
header_bytesize()
click to toggle source
# File lib/zip/crypto/traditional_encryption.rb, line 8 def header_bytesize 12 end
Protected Instance Methods
decrypt_byte()
click to toggle source
# File lib/zip/crypto/traditional_encryption.rb, line 33 def decrypt_byte temp = (@key2 & 0xffff) | 2 ((temp * (temp ^ 1)) >> 8) & 0xff end
reset_keys!()
click to toggle source
# File lib/zip/crypto/traditional_encryption.rb, line 18 def reset_keys! @key0 = 0x12345678 @key1 = 0x23456789 @key2 = 0x34567890 @password.each_byte do |byte| update_keys(byte.chr) end end
update_keys(num)
click to toggle source
# File lib/zip/crypto/traditional_encryption.rb, line 27 def update_keys(num) @key0 = ~Zlib.crc32(num, ~@key0) @key1 = ((@key1 + (@key0 & 0xff)) * 134_775_813 + 1) & 0xffffffff @key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2) end