-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
152 lines (117 loc) · 3.61 KB
/
index.html
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DecoderTestPage</title>
</head>
<body>
<div class="header">
<h1>Here you can test raw payload.</h1>
<p>Please enter payload_raw (Base64), e.g. from TTN; optionally multiple separated by spaces. <br>
Example: EQAAAAA= EQgAAAA="</p>
</div>
Base64:<br> <label for="textInput"></label><textarea id="textInput"></textarea> <br>
<button type="button" onclick="decodeFromHTML()">decode</button>
<div class="row">
<div class="column">
<h2>Interpretation</h2>
<pre id="result"></pre>
</div>
<div class="column">
<h2>input</h2>
<p id="displayInput">
</div>
</div>
<style>
#textInput {
}
#textInput{
display: inline-block; padding: 20px 10px; border: 5px solid #1C6EA4;
}
.header {
background-color: #f1f1f1;
padding: 20px;
text-align: center;
}
ul li {
border: 2px solid #1C6EA4;
display: inline-block;
background-color: lightgrey;
padding: 50px;
margin: 20px;
}
.column {
text-align: left;
background-color: lightgrey;
border: 15px solid #1C6EA4;
float: left;
width: 50%;
padding: 15px;
}
.row:after {
content: "";
display: table;
clear: both;
}
@media screen and (max-width:600px) {
.column {
width: 100%;
}
}
* {
box-sizing: border-box;
}
body {
background: #1C6EA4;
background: -moz-linear-gradient(left, #1C6EA4 0%, #2388CB 50%, #144E75 100%);
background: -webkit-linear-gradient(left, #1C6EA4 0%, #2388CB 50%, #144E75 100%);
background: linear-gradient(to right, #1C6EA4 0%, #2388CB 50%, #144E75 100%);
}
body {
min-height: 150px;
text-align: center;
}
</style>
<script src="decoder.js"></script>
<script>
function decodeFromHTML() {
let input = document.getElementById('textInput').value;
//let input = "EQAAAAA= EQgAAAA= EQEAAAA= ERAAAAA= EQQAAAA= ERgAAAA= EQgAAAA= ERkAAAA= oAIAfSU= oBwAYSY= oBwAdyY= oBwAcyU= oAIAaCU= oAIAaSU= oAIAfig= khwAAQIBAAEQAAhn0zJTAAA= kSwAcCUAAAAAAAA= kSoAcCYgAAAAAAA= EQQAAAA= EQwAAAA= kScBRCEhAAAAAAA= khwAAQIBAAEQAAhn0zJTAAA= oAIASSE=";
let inOut = (input).split(" ");
let inOutT = inOut.map(function (value,index,array) {
return "# " + index + ": " + value + "<br>";
});
testMyDecoder(input);
document.getElementById('displayInput').innerHTML = "Input: <br>" + inOutT;
}
function testMyDecoder(input) {
let testDataBase64 = (input).split(" ");
let testArrayBase16 = testDataBase64.map(base64ToBase16);
console.log(testArrayBase16);
let testArrayBytes = testArrayBase16.map(hexToBytes);
console.log(testArrayBytes);
let myObj = testArrayBytes.map(
function(value,index){
return new Decoder(value,index);
});
document.getElementById("result").innerHTML = JSON.stringify(myObj, undefined, 2);
}
function base64ToBase16(base64) {
return window.atob(base64)
.split('')
.map(function (aChar) {
return ('0' + aChar.charCodeAt(0).toString(16)).slice(-2);
})
.join('')
.toUpperCase();
}
function hexToBytes(hex) {
var bytes = [];
let c = 0;
for (bytes, c; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
</script>
</body>
</html>