fork download
  1. class Caesar_Cipher
  2. def initialize(plain, cipher_step)
  3. @plain = plain
  4. @cipher_step = cipher_step
  5. @crypted = crypt(@plain, @cipher_step)
  6. end
  7.  
  8. def crypt(plain, cipher_step)
  9. letters = plain.split(//)
  10. letters.map do |letter|
  11. if letter.scan(/\w/).length == 1
  12.  
  13. cipher_step.times do
  14. if (letter != 'z') && (letter != 'Z')
  15. letter.next!
  16. elsif (letter == 'z')
  17. letter = 'a'
  18. elsif (letter == 'Z')
  19. letter = 'A'
  20. end
  21. end
  22. end
  23. end
  24.  
  25. letters.join("")
  26. end
  27.  
  28. def out
  29. puts @crypted
  30. end
  31. end
  32.  
  33. mydecl = Caesar_Cipher.new("What a string!", 5)
  34. mydecl.out
Success #stdin #stdout 0.02s 9784KB
stdin
Standard input is empty
stdout
Zmfy f xywnsl!