# What kind of attacks is this code vulnerable to? [closed]

module SimpleCrypt

class Map
attr_accessor :letters

def initialize
@letters = ('a'..'z').to_a
@letters << "_"
@letters.shuffle!
end

end

class Cipher

def initialize(map)
@letters = map.letters
end

def mapping(type, character)
matches(@letters, type, character)
end

def matches(letters, type, character)
letters_copy = letters.dup
encrypt = Proc.new{|letter| "#{letter}#{character}#{letters_copy.shift}" }
decrypt = Proc.new{|letter| "#{letters_copy.shift}#{character}#{letter}" }
if type == "encrypt"
encrypt_map = ('a'..'z').to_a.map{ |letter|  encrypt[letter] }
encrypt_map << "_#{character}#{letters_copy.shift}"
else
encrypt_map = ('a'..'z').to_a.map{ |letter|  decrypt[letter] }.sort
encrypt_map << "#{letters_copy.shift}#{character}_"
end
end
end

class Encrypter < Cipher

def mapping
super('encrypt', @character)
end

def initialize(map, character = "=>")
super(map)
@character = character
end

end

class Decrypter < Cipher

def mapping
super('decrypt', @character)
end

def initialize(map, character = "=>")
super(map)
@character = character
end

end

end

map = SimpleCrypt::Map.new
encrypter = SimpleCrypt::Encrypter.new(map)
puts encrypter.mapping
puts ""
decrypter = SimpleCrypt::Decrypter.new(map)
puts decrypter.mapping

-
It would be helpful if you could explain what the code is doing. The code has quite a bit of syntactic sugar. –  Seth Sep 4 '11 at 0:09
Here is the output: gist.github.com/1191944#gistcomment-49027 –  Tyler Gillies Sep 4 '11 at 0:13
@Seth looks like it is Ruby. A quick glance makes me think this is a simple substitution cipher. In which case if you're directly transform English then it should be about as difficult to break as solving the cryptoquip in the newspaper. –  John Downey Sep 4 '11 at 0:17
We like the questions here on a more theoretic level - e.g., please describe your algorithm in English, instead of pasting a pile of code so we have to try to interpret it. –  Paŭlo Ebermann Sep 4 '11 at 0:39
This question appears to be off-topic because it asks to analyze code for security vulnerabilities. –  mikeazo Oct 3 '13 at 0:38

## closed as off-topic by e-sushi, B-Con, rath, mikeazo♦Oct 3 '13 at 0:38

• This question does not appear to be about cryptography within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.