Created
October 14, 2012 12:29
-
-
Save swistaczek/3888402 to your computer and use it in GitHub Desktop.
SimpleCipher
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
# encoding: utf-8 | |
class SimpleCipher | |
def initialize(randomized) | |
alphasum = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + [' '] | |
@map = alphasum.zip(randomized).inject(:encrypt => {} , :decrypt => {}) do |output,(a,b)| | |
output[:encrypt][a] = b | |
output[:decrypt][b] = a | |
output | |
end | |
end | |
def encrypt(input) | |
input.split(//).map { |char| @map[:encrypt][char] }.join | |
end | |
def decrypt(input) | |
input.split(//).map { |char| @map[:decrypt][char] }.join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment