Class: RubyRc4

Inherits:
Object
  • Object
show all
Defined in:
lib/RubyRc4.rb

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ RubyRc4

Returns a new instance of RubyRc4.



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/RubyRc4.rb', line 2

def initialize(str)
  @q1, @q2 = 0, 0
  @key = []
  str.each_byte {|elem| @key << elem} while @key.size < 256
  @key.slice!(256..@key.size-1) if @key.size >= 256
  @s = (0..255).to_a
  j = 0 
  0.upto(255) do |i| 
    j = (j + @s[i] + @key[i] )%256
    @s[i], @s[j] = @s[j], @s[i]
  end    
end

Instance Method Details

#encrypt(text) ⇒ Object



19
20
21
# File 'lib/RubyRc4.rb', line 19

def encrypt(text)
  process text.dup
end

#encrypt!(text) ⇒ Object



15
16
17
# File 'lib/RubyRc4.rb', line 15

def encrypt!(text)
  process text
end