Created
July 10, 2010 19:49
-
-
Save mattreduce/470973 to your computer and use it in GitHub Desktop.
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 | |
def initialize(input, shift_num) | |
@input, @shift_num = input.upcase, shift_num | |
end | |
def encrypt | |
shift_things_around | |
end | |
def decrypt | |
@shift_num = 26 - @shift_num | |
shift_things_around | |
end | |
private | |
def shift_things_around | |
@shift_num.times { @@alphabet.push(@@alphabet.shift) } | |
puts @input.tr('A-Z', @@alphabet.join) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment