Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Incognito-old
Path: blob/main/static/src/gs/public/breaklock/lab/bruteCalc.js
1330 views
1
#!/usr/bin/env node
2
3
if (!process.argv[2] || process.argv[2])
4
5
var patternLength = parseInt(process.argv[2]),
6
limit = 9,
7
proxies = [
8
[0,2,1],
9
[2,0,1],
10
[2,8,5],
11
[8,2,5],
12
[6,8,7],
13
[8,6,7],
14
[0,6,3],
15
[6,0,3],
16
[0,8,4],
17
[8,0,4],
18
[2,6,4],
19
[6,2,4]
20
]
21
22
if (!patternLength || patternLength < 1 || patternLength > limit) {
23
console.log('Usage: node bruteCalc.js patternLength')
24
console.log('Please use a valid \'patternLength\' value (between 1 and 9)')
25
process.exit(1)
26
}
27
28
function bf (length, stack, buffer) {
29
buffer = !buffer ? [] : buffer;
30
if (length <= 0) {
31
stack.push(buffer)
32
return stack
33
}
34
for (var i = 0; i < limit; i++) {
35
if (buffer.indexOf(i) != -1) {
36
continue
37
}
38
let pop = buffer[(buffer.length || 1) - 1]
39
if (buffer.length > 0 && proxies.find(pr => pr[0] == pop && pr[1] == i && buffer.indexOf(pr[2]) == -1)) {
40
continue
41
}
42
43
let clone = buffer.concat([])
44
clone.push(i)
45
bf(length-1,stack,clone)
46
}
47
return stack
48
}
49
50
var bfList = bf(patternLength, [])
51
52
bfList.forEach(s => console.log(s.join('')))
53
console.log('-----')
54
console.log('Pattern length : ' + patternLength)
55
console.log('Lock founds : ' + bfList.length)
56
57