Skip to content

Instantly share code, notes, and snippets.

@aspencer8111
Created June 22, 2015 20:09
Show Gist options
  • Save aspencer8111/69352f2e9b1d7459067a to your computer and use it in GitHub Desktop.
Save aspencer8111/69352f2e9b1d7459067a to your computer and use it in GitHub Desktop.
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
@aspencer8111
Copy link
Author

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment