Class: Cyphr
- Inherits:
-
Object
- Object
- Cyphr
- Defined in:
- lib/cyphrb.rb
Overview
should use a module?
Instance Method Summary collapse
- #descram(str) ⇒ Object
-
#initialize ⇒ Cyphr
constructor
A new instance of Cyphr.
- #scram(str) ⇒ Object
Constructor Details
#initialize ⇒ Cyphr
Returns a new instance of Cyphr.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cyphrb.rb', line 4 def initialize @cyph = {'a'=>'0', 'b'=>'1', 'c'=>'2', 'd'=>'3', 'e'=>'4', 'f'=>'5', 'g'=>'6', 'h'=>'7', 'i'=>'8', 'j'=>'9', 'k'=>'p', 'l'=>'o', 'm'=>'n', 'n'=>'m', 'o'=>'l', 'p'=>'k', 'q'=>'j', 'r'=>'i', 's'=>'h', 't'=>'g', 'u'=>'f', 'v'=>'e', 'w'=>'d', 'x'=>'c', 'y'=>'b', 'z'=>'a', '0'=>'q', '1'=>'r', '2'=>'s', '3'=>'t', '4'=>'u', '5'=>'v', '6'=>'w', '7'=>'x', '8'=>'y', '9'=>'z', 'A'=>'Z', 'B'=>'Y', 'C'=>'X', 'D'=>'W', 'E'=>'V', 'F'=>'U', 'G'=>'T', 'H'=>'S', 'I'=>'R', 'J'=>'Q', 'K'=>'P', 'L'=>'O', 'M'=>'N', 'N'=>'M', 'O'=>'L', 'P'=>'K', 'Q'=>'J', 'R'=>'I', 'S'=>'H', 'T'=>'G', 'U'=>'F', 'V'=>'E', 'W'=>'D', 'X'=>'C', 'Y'=>'B', 'Z'=>'A'} @dcyph = {'0'=>'a', '1'=>'b', '2'=>'c', '3'=>'d','4'=>'e','5'=>'f', '6'=>'g', '7'=>'h', '8'=>'i', '9'=>'j', 'p'=>'k', 'o'=>'l', 'n'=>'m', 'm'=>'n', 'l'=>'o', 'k'=>'p', 'j'=>'q', 'i'=>'r', 'h'=>'s', 'g'=>'t', 'f'=>'u', 'e'=>'v', 'd'=>'w', 'c'=>'x', 'b'=>'y', 'a'=>'z', 'q'=>'0', 'r'=>'1', 's'=>'2', 't'=>'3', 'u'=>'4', 'v'=>'5', 'w'=>'6', 'x'=>'7', 'y'=>'8', 'z'=>'9', 'Z'=>'A', 'Y'=>'B', 'X'=>'C', 'W'=>'D', 'V'=>'E', 'U'=>'F', 'T'=>'G', 'S'=>'H', 'R'=>'I', 'Q'=>'J', 'P'=>'K', 'O'=>'L', 'N'=>'M', 'M'=>'N', 'L'=>'O', 'K'=>'P', 'J'=>'Q', 'I'=>'R', 'H'=>'S', 'G'=>'T', 'F'=>'U', 'E'=>'V', 'D'=>'W', 'C'=>'X', 'B'=>'Y', 'A'=>'Z'} end |
Instance Method Details
#descram(str) ⇒ Object
34 35 36 |
# File 'lib/cyphrb.rb', line 34 def descram(str) str.gsub!(/[a-zA-Z0-9]/) { |match| @dcyph[match] } end |
#scram(str) ⇒ Object
30 31 32 |
# File 'lib/cyphrb.rb', line 30 def scram(str) str.gsub!(/[a-zA-Z0-9]/) { |match| @cyph[match] } end |