Created
October 27, 2017 09:36
-
-
Save DonMat/d8cfc33618284afce39011a631a7c3cf to your computer and use it in GitHub Desktop.
Infakt_workshops_challenge_2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CaesarCipher | |
@@alphabet = ('a'..'z').to_a.freeze | |
def initialize(text, rotate=13) | |
@text = text | |
@rotate = rotate | |
end | |
def perform | |
rotated_alphabet = @@alphabet.rotate(@rotate).to_s | |
rotated_alphabet_upcase = rotated_alphabet.upcase | |
@text.tr!(@@alphabet.to_s, rotated_alphabet.to_s) | |
@text.tr!(@@alphabet.to_s.upcase, rotated_alphabet_upcase.to_s) | |
@text | |
end | |
end | |
puts CaesarCipher.new("Testowy Tekst").perform | |
puts CaesarCipher.new("Ala ma...psa!", 4).perform |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment