-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (72 loc) · 2.56 KB
/
app.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
73
74
75
76
77
78
79
80
81
82
83
var messageOriginal = "Top Secret? Really?";
messageOriginal = messageOriginal.toUpperCase();
var messageCrypted = messageOriginal;
var cryptABC_Basic = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
var cryptABC=cryptABC_Basic;
var distanceKey = 3;
var cryptABCkeyword ="FÁBI LELLE LUCA";
var removeDuplicationsFromString = function(string) {
var array = Array.from(string);
for (var i=0; i<string.length; i++) {
for (var j=i+1; j<string.length; j++) {
if (array[j] === array[i]) {
delete(array[j]);
}
}
}
return array.join('');
}
var clearString = function(string, array) {
var arrayFromString = Array.from(string);
for (var i=0; i<string.length; i++) {
if (array.indexOf(arrayFromString[i]) <0) {
delete(arrayFromString[i]);
}
}
return arrayFromString.join('');
}
var modifyCryptABCWithKeyword = function (string, array) {
var arrayFromString = Array.from(string);
array = arrayFromString.concat(array);
for (var i=0; i<string.length; i++) {
for (var j = string.length; j<(array.length); j++) {
if (array[j] === arrayFromString[i] ) {
delete(array[j]);
}
}
}
var stringFromArray = array.join('');
return Array.from(stringFromArray);
}
var enCryptCaesar = function (string, array) {
arrayFromString = Array.from(string);
var result = [];
for (var i=0; i<string.length; i++) {
result[i] = array[(array.indexOf(arrayFromString[i])+distanceKey)%(array.length)];
}
return result.join('');
}
var deCryptCaesar = function (string, array) {
arrayFromString = Array.from(string);
var result = [];
for (var i=0; i<string.length; i++) {
result[i] = array[(array.indexOf(arrayFromString[i])+(26-distanceKey))%(array.length)];
}
return result.join('');
}
console.log(distanceKey);
console.log(cryptABCkeyword);
cryptABCkeyword = cryptABCkeyword.toUpperCase();
cryptABCkeyword = clearString(cryptABCkeyword,cryptABC);
cryptABCkeyword = removeDuplicationsFromString(cryptABCkeyword);
console.log(cryptABCkeyword);
console.log(cryptABC);
cryptABC = modifyCryptABCWithKeyword(cryptABCkeyword,cryptABC);
console.log(cryptABC);
messageOriginal = clearString(messageOriginal,cryptABC);
console.log(messageOriginal);
messageCrypted = enCryptCaesar(messageOriginal,cryptABC);
console.log(messageCrypted);
var secretMessage=messageCrypted;
secretMessage = deCryptCaesar(secretMessage,cryptABC);
console.log(secretMessage);