function decodeMessage var originalCanvas decode canvas var originalCo

 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
function decodeMessage() {
var $originalCanvas = $('.decode canvas');
var originalContext = $originalCanvas[0].getContext("2d");
var original = originalContext.getImageData(0, 0, $originalCanvas.width(), $originalCanvas.height());
var binaryMessage = "";
var pixel = original.data;
for (var i = 0, n = pixel.length; i < n; i += 4) {
for (var offset =0; offset < 3; offset ++) {
var value = 0;
if(pixel[i + offset] %2 != 0) {
value = 1;
}
binaryMessage += value;
}
}
var output = "";
for (var i = 0; i < binaryMessage.length; i += 8) {
var c = 0;
for (var j = 0; j < 8; j++) {
c <<= 1;
c |= parseInt(binaryMessage[i + j]);
}
output += String.fromCharCode(c);
}
$('.binary-decode textarea').text(output);
$('.binary-decode').fadeIn();
};