Skip to content

Instantly share code, notes, and snippets.

@swistaczek
Created October 14, 2012 12:29
Show Gist options
  • Save swistaczek/3888402 to your computer and use it in GitHub Desktop.
Save swistaczek/3888402 to your computer and use it in GitHub Desktop.
SimpleCipher
# 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