Module: RubyLabs::EncryptionLab
- Defined in:
- lib/encryptionlab.rb
Instance Method Summary collapse
-
#caesar(s, n = 3) ⇒ Object
:begin :caesar.
-
#rot(char, base, n) ⇒ Object
:end :caesar.
Instance Method Details
#caesar(s, n = 3) ⇒ Object
:begin :caesar
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/encryptionlab.rb', line 19 def caesar(s, n = 3) res = String.new s.each_byte do |byte| if byte >= ?a && byte <= ?z res << rot(byte, ?a, n) elsif byte >= ?A && byte <= ?Z res << rot(byte, ?A, n) else res << byte end end return res end |
#rot(char, base, n) ⇒ Object
:end :caesar
34 35 36 |
# File 'lib/encryptionlab.rb', line 34 def rot(char, base, n) return ((char - base) + n) % 26 + base end |