Skip to content

Instantly share code, notes, and snippets.

@DonMat
Created October 27, 2017 09:36
Show Gist options
  • Save DonMat/d8cfc33618284afce39011a631a7c3cf to your computer and use it in GitHub Desktop.
Save DonMat/d8cfc33618284afce39011a631a7c3cf to your computer and use it in GitHub Desktop.
Infakt_workshops_challenge_2
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