Class: Key::Caesar

Inherits:
SKey show all
Defined in:
lib/key/caesar.rb

Overview

Caesar

class for Caesar-like substitution ciphers: monoalphabetic with ordered alphabet

XXX Assume US-ASCII or lowest 256 chars of Unicode

Constant Summary

Constant Summary

Constants inherited from SKey

SKey::BASE

Instance Attribute Summary (collapse)

Attributes inherited from SKey

#alpha, #ralpha

Instance Method Summary (collapse)

Methods inherited from SKey

#decode, #encode

Constructor Details

- (Caesar) initialize(key)

Returns a new instance of Caesar



22
23
24
25
# File 'lib/key/caesar.rb', line 22

def initialize(key)
  super(key)
  gen_rings()
end

Instance Attribute Details

- (Object) offset (readonly)

Returns the value of attribute offset



20
21
22
# File 'lib/key/caesar.rb', line 20

def offset
  @offset
end

Instance Method Details

- (Object) gen_rings

gen_rings



29
30
31
32
33
34
35
36
37
# File 'lib/key/caesar.rb', line 29

def gen_rings
  @offset = @key.to_i

  BASE.scan(/./) do |c|
    d = ( (((c.ord - 65) + offset) % 26) + 65).chr
    @alpha[c]  = d
    @ralpha[d] = c
  end
end