Class: Key::Caesar
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
Instance Attribute Summary (collapse)
-
- (Object) offset
readonly
Returns the value of attribute offset.
Attributes inherited from SKey
Instance Method Summary (collapse)
-
- (Object) gen_rings
gen_rings.
-
- (Caesar) initialize(key)
constructor
A new instance of Caesar.
Methods inherited from SKey
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 |