### Home Classes Methods

### In Files

- lib/prawn/security/arcfour.rb

### Parent

Object

### Methods

- ::new
- #encrypt

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Configurable
- Prawn::Document
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::GraphicsState
- Prawn::Document::Grid
- Prawn::Document::GridBox
- Prawn::Document::Internals
- Prawn::Document::Security
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::FontMetricCache
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Patterns
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::ImageHandler
- Prawn::Images
- Prawn::Images::Image
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::SoftMask
- Prawn::Stamp
- Prawn::SynchronizedCache
- Prawn::Table
- Prawn::Table::Cell
- Prawn::Table::Cell::Image
- Prawn::Table::Cell::InTable
- Prawn::Table::Cell::SpanDummy
- Prawn::Table::Cell::Subtable
- Prawn::Table::Cell::Text
- Prawn::Table::Cells
- Prawn::Table::ColumnWidthCalculator
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::Formatted
- Prawn::Text::Formatted::Box
- Prawn::Text::Formatted::Fragment
- Prawn::Text::Formatted::Parser
- Prawn::ThreadLocalCache
- PDF
- PDF::Core
- PDF::Core::Reference
- PDF::Core::Stream
- Arcfour
- Numeric

No matching classes.

# Arcfour

@private

### Public Class Methods

new(key) click to toggle source

    # File lib/prawn/security/arcfour.rb, line 13
    def initialize(key)
      # Convert string key to Array of integers
      key = key.unpack('c*') if key.is_a?(String)

      # 1. Allocate an 256 element array of 8 bit bytes to be used as an S-box
      # 2. Initialize the S-box.  Fill each entry first with it's index
      @sbox = (0..255).to_a

      # 3. Fill another array of the same size (256) with the key, repeating
      #    bytes as necessary.
      s2 = []
      while s2.length < 256
        s2 += key
      end
      s2 = s2[0, 256]

      # 4. Set j to zero and initialize the S-box
      j = 0
      (0..255).each do |i|
        j = (j + @sbox[i] + s2[i]) % 256
        @sbox[i], @sbox[j] = @sbox[j], @sbox[i]
      end

      @i = @j = 0
    end

### Public Instance Methods

encrypt(string) click to toggle source

    # File lib/prawn/security/arcfour.rb, line 39
    def encrypt(string)
      string.unpack('c*').map{|byte| byte ^ key_byte}.pack('c*')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.