fork download
  1. module CaesarCipher
  2. def self.encrypt(s, shift)
  3. s.bytes.map { |b| ((b + shift) % 0xFF).chr }.join
  4. end
  5.  
  6. def self.decrypt(s, shift)
  7. s.bytes.map { |b| ((b - shift + 0xFF) % 0xFF).chr }.join
  8. end
  9. end
  10.  
  11. KEY = 33
  12.  
  13. input = gets
  14. encrypted = CaesarCipher.encrypt input, KEY
  15. decrypted = CaesarCipher.decrypt encrypted, KEY
  16. puts decrypted
Success #stdin #stdout 0.05s 9704KB
stdin
Привет, Мир!
stdout
Привет, Мир!