Converted the decoder from python into javascript – technically Coffeescript, which is dynamically compiled into JS in your browser (magic!)  It’s very straight-forward once everything is properly setup – Jessica Allen has a cute guide on it.  This is going to be useful moving forward converting the buncha python things to the browser.  Can’t figure out how to integrate this into a WordPress page – another battle for another day. In the meantime, here’s the decoder on its own page:

Decoder

 

 

The simple snipplet responsible in Javascript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var decodeMnemonic, input, mapping, output;
input = 'bananas';
output = '';
mapping = {1: "l", 2: "n", 3: "m", 4: "r", 5: "s", 6: "b", 7: "t", 8: "f", 9: "g", 0: "d"};
decodeMnemonic = function(x) {
var i, num, result, text, _ref;
result = "";
x = x.toLowerCase();
for (i = 0, _ref = x.length - 1; (0 <= _ref ? i <= _ref : i >= _ref); (0 <= _ref ? i += 1 : i -= 1)) {
for (num in mapping) {
text = mapping[num];
if (text === x.charAt(i)) {
result = result + num;
}
}
}
return result;
};
alert(decodeMnemonic(input));

And in Coffeescript (sorry, CodeColorer doesn’t support coffeescript, so this is ruby highlight):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
input = 'Bananas'
output = ''
mapping = {1: "l", 2: "n", 3: "m", 4: "r", 5: "s", 6: "b", 7: "t", 8: "f", 9: "g", 0: "d"}

decodeMnemonic = (x) ->
  result = ""
  x = x.toLowerCase()
  for i in [0..(x.length-1)]
    for num,text of mapping
      if (text == x.charAt(i))
        result = result + num
  return result

alert(decodeMnemonic(input))

…and in python, which is almost identical to the coffeescript:

1
2
3
4
5
6
7
8
9
10
mapping = {"1": "l", "2": "n", "3": "m", "4": "r", "5": "s", "6": "b", "7": "t", "8": "f", "9": "g", "0": "d"}

def decodeMnemonic(x):
  result = ""
  x = x.lower()
  for i in x:
    for key in mapping:
      if (mapping[key] == i):
        result = result + key
  return result