-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
57 lines (45 loc) · 1.65 KB
/
Copy pathapp.js
File metadata and controls
57 lines (45 loc) · 1.65 KB
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
const checkAgree = require('./checkAgree');
const checkPirson = require('./checkPirson');
const decrypt = require('./decrypt');
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const shuffle = (a) => {
let j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;
}
return a;
};
const text = 'EFFPQLMEHEMVPCPYFLMVHQLUHYTCETHQEKLPVMMVHQLUWEOLFPQLIVDLWLULMVHQLUCYAUHUYDUEOSQYATFFVSMUVOVWEPLPQVSPCHLYGETDYUVPQOGUYOOYWYETHQEKLPVMYWLSASVWDEWCPLSPYGDYYFWLSSYGGVPCYAEULMYOGYUPEKTLBVPQCYAOECASLVWFLRYGMYVWMVFLWMLNESVSNVLREOVWEPVYWSPEPVSPVMETPLSPSYUBQEPLILUOLPQYFCYAGLLTBVTTSQYBPQLKLSPULSATPPUCPYPQVWNYGBQEPBVTTQEHHLWVGPQLNLCMYWPEVWSSEOLMQEUEMPLUSEPFVGGLULWPHYSVPVYWSBVTTCYAUHUYDUEOSPVTTKLQEILMYUULMPTC';
let bestKey = alphabet.split('');
let bestCriteria = 99999999999999;
let i = 0;
while (i < 10) {
let bestRandKey = Object.assign([], bestKey);
shuffle(bestRandKey);
let bestRandCriteria = checkPirson(decrypt(text, bestRandKey));
let j = 0;
while (j < 1000) {
const a = Math.floor(Math.random() * 26);
const b = Math.floor(Math.random() * 26);
const key = Object.assign([], bestRandKey);
const t = key[a];
key[a] = key[b];
key[b] = t;
const criteria = checkPirson(decrypt(text, key));
if (criteria < bestRandCriteria) {
bestRandCriteria = criteria;
bestRandKey = key;
j = 0;
}
j++;
}
if (bestRandCriteria < bestCriteria) {
bestCriteria = bestRandCriteria;
bestKey = bestRandKey;
}
i++;
}
console.log(bestCriteria, checkPirson(decrypt(text, bestKey)), bestKey.join(''), decrypt(text, bestKey));