-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculateStrongEntropy.js
140 lines (89 loc) · 3.71 KB
/
calculateStrongEntropy.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import calculateStrongEntropy from 'eslint-plugin-no-credentials/calculateStrongEntropy';
import expect from 'eslint-plugin-no-credentials/tests-mocha/expect';
describe('calculateStrongEntropy', () => {
it('calculates strong entropy for an empty string', () => {
const string = '';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(0, 0.00001);
});
it('calculates strong entropy for a', () => {
const string = 'a';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(1, 0.00001);
});
it('calculates strong entropy for aaaaa', () => {
const string = 'aaaaa';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(1.73205, 0.00001);
});
it('calculates strong entropy for abcde', () => {
const string = 'abcde';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(4.07549, 0.00001);
});
it('calculates strong entropy for foo', () => {
const string = 'foo';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(2.39893, 0.00001);
});
it('calculates strong entropy for foofoofoo', () => {
const string = 'foofoofoo';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(3.09701, 0.00001);
});
it('calculates strong entropy for foo repeated 10 times', () => {
const string = 'foo'.repeat(10);
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(3.09701, 0.00001);
});
it('calculates strong entropy for foo repeated 100 times', () => {
const string = 'foo'.repeat(100);
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(3.66443, 0.00001);
});
it('calculates strong entropy for foo1foo2foo', () => {
const string = 'foo1foo2foo';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(4.85332, 0.00001);
});
it('calculates strong entropy for foobarbaz', () => {
const string = 'foobarbaz';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(5.61509, 0.00001);
});
it('calculates strong entropy for a random 9-characters string', () => {
const string = 'wYPT0KmIp';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(6.12611, 0.00001);
});
it('calculates strong entropy for a random 12-characters string', () => {
const string = 'tBfsfGjuw7Nc';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(7.28145, 0.00001);
});
it('calculates strong entropy for a random 12-characters 01 sequence', () => {
const string = '101001010001';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(4.22123, 0.00001);
});
it('calculates strong entropy for a random 32-characters 01 sequence', () => {
const string = '10001011101100010100100011000111';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(5.82684, 0.00001);
});
it('calculates strong entropy for a random 12-characters digits sequence', () => {
const string = '676158717724';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(6.55892, 0.00001);
});
it('calculates strong entropy for a random 32-characters digits sequence', () => {
const string = '45220077709114486712228402662775';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(10.55522, 0.00001);
});
it('calculates strong entropy for aą#$@;,vŽžő', () => {
const string = 'aą#$@;,vŽžő';
const result = calculateStrongEntropy(string);
expect(result).to.be.closeTo(8.44694, 0.00001);
});
});