Skip to content

Instantly share code, notes, and snippets.

@mattreduce
Created July 10, 2010 19:49
Show Gist options
  • Save mattreduce/470973 to your computer and use it in GitHub Desktop.
Save mattreduce/470973 to your computer and use it in GitHub Desktop.
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