Class: Cipher::Skip32

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

Overview

A 32-bit version of the SKIPJACK cipher. This interface is not intended to be compatible with the OpenSSL::Cipher modules.

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Skip32

Returns a new instance of Skip32.

Parameters:

  • key (String)

    the key

Raises:

  • (Error)

    if key is too short



12
13
14
15
# File 'lib/cipher/skip32.rb', line 12

def initialize(key)
  raise Error, "key length too short" if key.length < key_len
  @key = key.unpack("C*")
end

Instance Method Details

#block_sizeInteger

Returns the block size

Returns:

  • (Integer)

    the block size



43
44
45
# File 'lib/cipher/skip32.rb', line 43

def block_size
  4
end

#decrypt(block) ⇒ String

Decrypts block and returns the result

Returns:

  • (String)

    the decrypted block

Raises:

  • (Error)

    if block is too short



29
30
31
32
33
# File 'lib/cipher/skip32.rb', line 29

def decrypt(block)
  buffer = unpack(block)
  skip32(@key, buffer, false)
  pack(buffer)
end

#encrypt(block) ⇒ String

Encrypts block and returns the result

Returns:

  • (String)

    the encrypted block

Raises:

  • (Error)

    if block is too short



20
21
22
23
24
# File 'lib/cipher/skip32.rb', line 20

def encrypt(block)
  buffer = unpack(block)
  skip32(@key, buffer, true)
  pack(buffer)
end

#inspectString

Returns a string representation of the object

Returns:

  • (String)

    a string representation of the object



37
38
39
# File 'lib/cipher/skip32.rb', line 37

def inspect
  "#<Cipher::Skip32:#{object_id}>"
end

#key_lenInteger

Returns the key length

Returns:

  • (Integer)

    the key length



49
50
51
# File 'lib/cipher/skip32.rb', line 49

def key_len
  10
end