Skip to content

Instantly share code, notes, and snippets.

@erickgirard
Last active December 15, 2015 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erickgirard/5340049 to your computer and use it in GitHub Desktop.
Save erickgirard/5340049 to your computer and use it in GitHub Desktop.
Code hulk text decoder http://codehulk.lunarlogicpolska.com
class CodeHulk
def self.decode(encoded_text)
decoded_text = ''
text = encoded_text
text = text.gsub(@@start_encoded_text, '')
text = text.gsub(@@end_encoded_text, '')
text.split('').each do |c|
if(@@dictionary.include?(c))
decoded_text << @@dictionary[c]
else
decoded_text << c
end
end
return decoded_text
end
private
@@start_encoded_text = "==BEGIN-ENCODED-MESSAGE=="
@@end_encoded_text = "==END-ENCODED-MESSAGE=="
@@dictionary = {
's' => 'a',
'W' => 'b',
'3' => 'B',
'U' => 'c',
't' => 'C',
'v' => 'd',
'0' => 'D',
'E' => 'e',
'b' => 'E',
'm' => 'f',
'1' => 'g',
'n' => 'G',
'?' => 'h',
'B' => 'H',
'J' => 'i',
'w' => 'I',
'I' => 'k',
'8' => 'l',
'd' => 'm',
'y' => 'M',
'r' => 'n',
'R' => 'o',
'o' => 'p',
'H' => 'q',
'x' => 'r',
'K' => 'R',
'a' => 's',
'O' => 'S',
'2' => 't',
'!' => 'T',
'4' => 'u',
'l' => 'v',
'6' => 'y',
'S' => 'Y',
'F' => 'z',
'A' => '-',
'D' => '.',
':' => ':',
'9' => '?',
'7' => ' ',
'h' => '!',
',' => ',',
'-' => '0',
'j' => '1',
'N' => '2',
'M' => '3',
'i' => '4',
'.' => '5',
'C' => '6',
'f' => '7',
'G' => '8',
'X' => '9',
}
end
file_to_read = ARGV[0]
if(File.exists?(file_to_read))
text = File.open(file_to_read).read
puts "Encoded Text:\n"
puts text
puts "Decoded text:\n"
puts CodeHulk.decode(text)
else
puts 'Error need a valid file'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment