class Caesar_Cipher
def initialize(plain, cipher_step)
@plain = plain
@cipher_step = cipher_step
@crypted = crypt(@plain, @cipher_step)
end
def crypt(plain, cipher_step)
letters = plain.split(//)
letters.map do |letter|
if letter.scan(/\w/).length == 1
cipher_step.times do
if (letter != 'z') && (letter != 'Z')
letter.next!
elsif (letter == 'z')
letter = 'a'
elsif (letter == 'Z')
letter = 'A'
end
end
end
end
letters.join("")
end
def out
puts @crypted
end
end
mydecl = Caesar_Cipher.new("What a string!", 5)
mydecl.out
Y2xhc3MgQ2Flc2FyX0NpcGhlcgoJZGVmIGluaXRpYWxpemUocGxhaW4sIGNpcGhlcl9zdGVwKQoJCUBwbGFpbiA9IHBsYWluCgkJQGNpcGhlcl9zdGVwID0gY2lwaGVyX3N0ZXAKCQlAY3J5cHRlZCA9IGNyeXB0KEBwbGFpbiwgQGNpcGhlcl9zdGVwKQoJZW5kCgoJZGVmIGNyeXB0KHBsYWluLCBjaXBoZXJfc3RlcCkKCQlsZXR0ZXJzID0gcGxhaW4uc3BsaXQoLy8pCgkJbGV0dGVycy5tYXAgZG8gfGxldHRlcnwKCQkJaWYgbGV0dGVyLnNjYW4oL1x3LykubGVuZ3RoID09IDEKCgkJCQljaXBoZXJfc3RlcC50aW1lcyBkbwoJCQkJCWlmIChsZXR0ZXIgIT0gJ3onKSAmJiAobGV0dGVyICE9ICdaJykKCQkJCQkJbGV0dGVyLm5leHQhCgkJCQkJZWxzaWYgKGxldHRlciA9PSAneicpCgkJCQkJCWxldHRlciA9ICdhJwoJCQkJCWVsc2lmIChsZXR0ZXIgPT0gJ1onKQoJCQkJCQlsZXR0ZXIgPSAnQScKCQkJCQllbmQKCQkJCWVuZAoJCQllbmQKCQllbmQKCgkJbGV0dGVycy5qb2luKCIiKQoJZW5kCgoJZGVmIG91dAoJCXB1dHMgQGNyeXB0ZWQKCWVuZAplbmQKCm15ZGVjbCA9IENhZXNhcl9DaXBoZXIubmV3KCJXaGF0IGEgc3RyaW5nISIsIDUpCm15ZGVjbC5vdXQ=