Module: Smbhash::Methods19

Defined in:
lib/smbhash/methods19.rb

Instance Method Summary collapse

Instance Method Details

#convert_encoding(to, from, str) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/smbhash/methods19.rb', line 21

def convert_encoding(to, from, str)
  if same_encoding?(to, from)
    str
  else
    str.encode(to, from)
  end
end

#str_to_key(str) ⇒ Object



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

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

  key.size.times do |i|
    key.setbyte(i, (key.getbyte(i) << 1));
  end

  key
end