Method: PDF::Writer::ARC4#init

Defined in:
lib/extensions/pdf-writer/pdf/writer/arc4.rb

#init(key) ⇒ Object

Initialize the ARC4 encryption.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/extensions/pdf-writer/pdf/writer/arc4.rb', line 28

def init(key)
  @arc4 = ""

    # Setup the control array
  return if key.empty?

  a = []
  (0..255).each { |ii| a[ii] = "%c" % ii }

  k = (key * 256)[0..255].split(//)

  jj = 0
  @arc4.each_with_index do |el, ii|
    jj = ((jj + el.to_i) + k[ii].to_i) % 256
    a[ii], a[jj] = a[jj], a[ii]
  end
  @arc4 = a.join
end