-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipv72.js
47 lines (38 loc) · 1.18 KB
/
ipv72.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
const getSequences = (net) => {
const sequences = [];
for (let i = 0; i < net.length - 2; i++) {
if (net[i + 0] === net[i + 2] && // first and third the same
net[i + 0] !== net[i + 1]) { // first and second not the same
sequences.push(net.slice(i, i + 3));
}
}
return sequences;
};
const reverse = (sequence) => {
return sequence[1] + sequence[0] + sequence[1];
};
const supportsSsl = (ip) => {
const parts = ip.match(/(\w+)\[(\w+)\](\w+)(?:\[(\w+)\])?(\w+)?(?:\[(\w+)\])?(\w+)?/);
const abas = [parts[1], parts[3], parts[5], parts[7]]
.filter((x) => x)
.map((net) => getSequences(net))
.reduce((previousValue, currentValue) => [...previousValue, ...currentValue], []);
const babs = [parts[2], parts[4], parts[6]]
.filter((x) => x)
.map((net) => getSequences(net))
.reduce((previousValue, currentValue) => [...previousValue, ...currentValue], []);
return abas.length &&
babs.length &&
abas.some((aba) => babs.some((bab) => reverse(bab) === aba));
};
const countIps = (input) => {
return input
.split('\n')
.map(supportsSsl)
.filter((x) => x)
.length;
};
module.exports = {
countIps,
supportsSsl,
};