fork download
  1. ############################################################
  2. #
  3. # Name: den510
  4. # Date: 04/25/17
  5. # Challenge: #312 L33tspeak
  6. # Description: Translate to and from 1337
  7. #
  8. ############################################################
  9.  
  10. $leet_dictionary = {
  11. 'A' => '4',
  12. 'B' => '6',
  13. 'E' => '3',
  14. 'L' => '1',
  15. 'I' => '|',
  16. 'M' => '(V)',
  17. 'N' => '(\)',
  18. 'O' => '0',
  19. 'S' => '5',
  20. 'T' => '7',
  21. 'V' => '\/',
  22. 'W' => '`//'
  23. }
  24.  
  25. def muggle_to_leet(word)
  26. $leet_dictionary.keys.each { |key| word.gsub!(key, $leet_dictionary[key]) }
  27. word
  28. end
  29.  
  30. def leet_to_muggle(word)
  31. $leet_dictionary.values.each { |value| word.gsub!(value, $leet_dictionary.key(value)) }
  32. word
  33. end
  34.  
  35. def ez_leet(word)
  36. word.upcase!
  37. $leet_dictionary.values.each { |value| return leet_to_muggle(word) if word.include?(value.to_s) }
  38. muggle_to_leet(word)
  39. end
  40.  
  41. puts ez_leet('31337')
  42. puts ez_leet('storm')
  43.  
  44. puts ez_leet('I am elite.')
  45. puts ez_leet('Da pain!')
  46. puts ez_leet('Eye need help!')
  47. puts ez_leet('3Y3 (\)33d j00 t0 g37 d4 d0c70r.')
  48. puts ez_leet('| n33d m4 p|llz!')
Success #stdin #stdout 0s 28688KB
stdin
Standard input is empty
stdout
ELEET
570R(\/)
| 4(\/) 31|73.
D4 P4|(\)!
3Y3 (\)33D H31P!
EYE NEED JOO TO GET DA DOCTOR.
I NEED MA PILLZ!