forked from EntropyString/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentropy.js
More file actions
65 lines (50 loc) · 1.39 KB
/
entropy.js
File metadata and controls
65 lines (50 loc) · 1.39 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
58
59
60
61
62
63
64
65
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _log = require('babel-runtime/core-js/math/log10');
var _log3 = _interopRequireDefault(_log);
var _log4 = require('babel-runtime/core-js/math/log2');
var _log5 = _interopRequireDefault(_log4);
var _lcm = require('./lcm');
var _lcm2 = _interopRequireDefault(_lcm);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _log2 = _log5.default;
var _log10 = _log3.default;
var _log2_10 = _log2(10);
var _bitsPerByte = 8;
var _totalOf = function _totalOf(numStrings, log2Risk) {
if (numStrings == 0) {
return 0;
}
var N = void 0;
if (numStrings < 1000) {
N = _log2(numStrings) + _log2(numStrings - 1);
} else {
N = 2 * _log2(numStrings);
}
return N + log2Risk - 1;
};
var bits = function bits(total, risk) {
if (total == 0) {
return 0;
}
return _totalOf(total, _log2(risk));
};
var bitsWithRiskPower = function bitsWithRiskPower(total, rPower) {
var log2Risk = _log2_10 * rPower;
return _totalOf(total, log2Risk);
};
var bitsWithPowers = function bitsWithPowers(tPower, rPower) {
var N = 0;
if (tPower < 4) {
return bitsWithRiskPower(Math.pow(10, tPower), rPower);
} else {
return (2 * tPower + rPower) * _log2_10 - 1;
}
};
exports.default = {
bits: bits,
bitsWithRiskPower: bitsWithRiskPower,
bitsWithPowers: bitsWithPowers
};