Created
June 22, 2015 20:09
-
-
Save aspencer8111/69352f2e9b1d7459067a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Rot13 | |
attr_accessor :text | |
def initialize(text) | |
@text = text | |
end | |
def encrypt | |
@text = @text.tr('a-zA-Z', 'n-za-mN-ZA-M') | |
end | |
def decrypt | |
@text = @text.tr('n-za-mN-ZA-M', 'a-zA-Z') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
Encrypt:
Rot13.new("This is my string").encrypt #returns 'Guvf vf zl fgevat'
Decrypt:
Rot13.new("Guvf vf zl fgevat").decrypt #returns 'This is my string'