Class: CombinePDF::RC4

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

Overview

The following isn’t my code!!!! It is subject to a different license and copyright. This was the code for the RC4 Gem, … I had a bad internet connection so I ended up copying it from the web page I had in my cache. This wonderful work was done by Caige Nichols.

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ RC4



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/combine_pdf/combine_pdf_decrypt.rb', line 156

def initialize(str)
  begin
    raise SyntaxError, "RC4: Key supplied is blank"  if str.eql?('')

    @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
end

Instance Method Details

#encrypt(text) ⇒ Object Also known as: decrypt



177
178
179
# File 'lib/combine_pdf/combine_pdf_decrypt.rb', line 177

def encrypt(text)
  process text.dup
end

#encrypt!(text) ⇒ Object



173
174
175
# File 'lib/combine_pdf/combine_pdf_decrypt.rb', line 173

def encrypt!(text)
  process text
end