-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (28 loc) · 982 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function encode() {
var output = document.getElementsByClassName("caixa2")[0];
var input = document.getElementsByClassName("caixa1")[0];
output.value = "";
for (var i = 0; i < input.value.length; i++) {
output.value += input.value[i].charCodeAt(0).toString(2) + " ";
}
output.value = output.value.slice(0, output.value.length - 1);
input.value = "";
}
function decode() {
var input = document.getElementsByClassName("caixa2")[0];
var output = document.getElementsByClassName("caixa1")[0];
output.value = "";
var letras = input.value.split(" ");
var binCode = [];
for (const element of letras) {
binCode.push(String.fromCharCode(parseInt(element, 2)));
}
output.value = binCode.join("");
input.value = "";
}
window.onload = function () {
var botao1 = document.getElementsByName("botao1");
var botao2 = document.getElementsByName("botao2");
botao1[0].addEventListener("click", encode);
botao2[0].addEventListener("click", decode);
};