class Net::NTLM::Rc4
libssl-3.0+ doesn’t support legacy Rc4
-> use our own implementation
Openssl/libssl provides RC4, so we can use it.
Constants
- INITIAL_STATE
The initial state which is then modified by the key-scheduling algorithm
Public Class Methods
new(str)
click to toggle source
# File lib/net/ntlm/rc4.rb, line 12 def initialize(str) raise ArgumentError, "RC4: Key supplied is blank" if str.eql?('') initialize_state(str) @q1, @q2 = 0, 0 end
Public Instance Methods
encrypt(text)
click to toggle source
# File lib/net/ntlm/rc4.rb, line 18 def encrypt(text) text.each_byte.map do |b| @q1 = (@q1 + 1) % 256 @q2 = (@q2 + @state[@q1]) % 256 @state[@q1], @state[@q2] = @state[@q2], @state[@q1] b ^ @state[(@state[@q1] + @state[@q2]) % 256] end.pack("C*") end
Private Instance Methods
initialize_state(key)
click to toggle source
Performs the key-scheduling algorithm to initialize the state.
# File lib/net/ntlm/rc4.rb, line 33 def initialize_state(key) i = j = 0 @state = INITIAL_STATE.dup key_length = key.length while i < 256 j = (j + @state[i] + key.getbyte(i % key_length)) % 256 @state[i], @state[j] = @state[j], @state[i] i += 1 end end