-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypt.js
72 lines (64 loc) · 2.01 KB
/
decrypt.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
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
//Global Variables
var image1;
var image2;
var canvas1;
var canvas2;
var context1;
var context2;
var characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+=-*, ."
//Start Up Process
function initiate() {
var button = document.getElementById('Decrypt');
image1 = document.getElementById('decrypt-original');
image2 = document.getElementById('decrypt-modified');
canvas1 = document.getElementById('Canvas2');
canvas2 = document.getElementById('Canvas3');
canvas1.height = image1.height;
canvas1.width = image1.width;
canvas2.height = image2.height;
canvas2.width = image2.width;
context1 = canvas1.getContext('2d');
context2 = canvas2.getContext('2d');
button.addEventListener('click', imgDrawing(image1, context1));
button.addEventListener('click', imgDrawing(image2, context2));
}
//Send Image to Canvas
function imgDrawing(image, ctx) {
ctx.drawImage(image, 0, 0);
}
//Access the Image Data
function ImageData() {
var imagedata1 = context1.getImageData(0, 0, canvas1.width, canvas1.height);
var imagedata2 = context2.getImageData(0, 0, canvas2.width, canvas2.height);
console.log(imagedata1);
console.log(imagedata2);
decrypt(imagedata1.data, imagedata2.data);
}
//Decryption Function
function decrypt(dataOne, dataTwo) {
var shortHistory = "";
var message = "";
var incorrect = 0;
//Decryption Algorithm
for (var i = 0; i < dataOne.length; i++) {
shortHistory = "";
if (dataOne[i] == dataTwo[i]) {
//Keep Empty
}else{
if (dataOne[i] > dataTwo[i]) {
shortHistory += dataOne[i] - dataTwo[i];
}else {
shortHistory += dataTwo[i] - dataOne[i];
}
}
//Number to Text Conversion
if (shortHistory > 0) {
console.log("Message: " + characters.charAt(shortHistory - 1));
console.log("Shorthistory: " + shortHistory);
message += characters.charAt(shortHistory - 1)
}
}
document.getElementById('decrypted-message').innerHTML = message;
}
//Start the Program
window.addEventListener('load', initiate);