Last active
January 15, 2020 16:49
-
-
Save elucid/c511c54bc71fb5f24aa9f0aa0b1d49e7 to your computer and use it in GitHub Desktop.
Decoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const decoder = | |
{ | |
4: "A", | |
7: "B", | |
5: "C", | |
9: "D", | |
6: "E", | |
8: "F", | |
10: "G", | |
24: "H", | |
1: "I", | |
25: "J", | |
15: "K", | |
14: "L", | |
12: "M", | |
13: "N", | |
3: "O", | |
11: "P", | |
16: "Q", | |
17: "R", | |
23: "S", | |
26: "T", | |
21: "U", | |
19: "V", | |
18: "W", | |
20: "X", | |
22: "Y", | |
2: "Z", | |
}; | |
const encoder = (function() { | |
var res = {}; | |
for (var k in decoder) { | |
if (decoder.hasOwnProperty(k)) { | |
res[decoder[k]] = k; | |
} | |
} | |
return res; | |
})(); | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
actions: { | |
decode: function() { | |
var cipher = this.get('cipher') || ''; | |
var message = cipher.replace(/\d+/g, function(d) { | |
return decoder[d] || d; | |
}).replace(/-/g, ''); | |
this.set('message', message); | |
}, | |
encode: function() { | |
var message = this.get('message') || ''; | |
var cipher = message.replace(/(\w+)/g, function(s, word) { | |
return word.toUpperCase().split('').map(function(letter) { | |
return encoder[letter] || letter; | |
}).join('-'); | |
}); | |
this.set('cipher', cipher); | |
}, | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment