Class: Sc2::Hasher
- Inherits:
-
Object
- Object
- Sc2::Hasher
- Defined in:
- lib/sc2/magick/hasher.rb
Instance Method Summary collapse
- #decrypt(data, seed1) ⇒ Object
- #hash_for(hash_type, s) ⇒ Object
-
#initialize ⇒ Hasher
constructor
A new instance of Hasher.
Constructor Details
#initialize ⇒ Hasher
Returns a new instance of Hasher.
3 4 5 |
# File 'lib/sc2/magick/hasher.rb', line 3 def initialize set_enc_tbl end |
Instance Method Details
#decrypt(data, seed1) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sc2/magick/hasher.rb', line 18 def decrypt data, seed1 seed2 = 0xEEEEEEEE data.unpack('V*').map do |value| seed2 = (seed2 + @encryption_table[0x400 + (seed1 & 0xFF)]) & 0xFFFFFFFF value = (value ^ (seed1 + seed2)) & 0xFFFFFFFF seed1 = (((~seed1 << 0x15) + 0x11111111) | (seed1 >> 0x0B)) & 0xFFFFFFFF seed2 = (value + seed2 + (seed2 << 5) + 3) & 0xFFFFFFFF value end.pack('V*') end |
#hash_for(hash_type, s) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sc2/magick/hasher.rb', line 7 def hash_for hash_type, s hash_type = [:table_offset, :hash_a, :hash_b, :table].index hash_type seed1, seed2 = 0x7FED7FED, 0xEEEEEEEE s.upcase.each_byte do |c| value = @encryption_table[(hash_type << 8) + c] seed1 = (value ^ (seed1 + seed2)) & 0xFFFFFFFF seed2 = (c + seed1 + seed2 + (seed2 << 5) + 3) & 0xFFFFFFFF end seed1 end |