(code: string)
| 28 | } |
| 29 | |
| 30 | function estimateEntropy(code: string): number { |
| 31 | const freq: Record<string, number> = {} |
| 32 | |
| 33 | for (const d of code) freq[d] = (freq[d] || 0) + 1 |
| 34 | |
| 35 | let entropy = 0 |
| 36 | for (const k in freq) { |
| 37 | const p = freq[k] / code.length |
| 38 | entropy -= p * Math.log2(p) |
| 39 | } |
| 40 | |
| 41 | return entropy * code.length |
| 42 | } |
| 43 | |
| 44 | function collisionRisk( |
| 45 | code: string, |