Module: Smbhash::Methods18

Defined in:
lib/smbhash/methods18.rb

Instance Method Summary collapse

Instance Method Details

#convert_encoding(to, from, str) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/smbhash/methods18.rb', line 23

def convert_encoding(to, from, str)
  if same_encoding?(to, from)
    str
  else
    Iconv.iconv(to, from, str).join
  end
end

#str_to_key(str) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/smbhash/methods18.rb', line 5

def str_to_key(str)
  key = "\000" * 8
  key[0] = str[0] >> 1;
  key[1] = ((str[0] & 0x01) << 6) | (str[1] >> 2);
  key[2] = ((str[1] & 0x03) << 5) | (str[2] >> 3);
  key[3] = ((str[2] & 0x07) << 4) | (str[3] >> 4);
  key[4] = ((str[3] & 0x0F) << 3) | (str[4] >> 5);
  key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6);
  key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7);
  key[7] = str[6] & 0x7F;

  key.size.times do |i|
    key[i] = (key[i] << 1);
  end

  key
end