Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetEntropy(text)
- {
- var result = 0;
- var stat = Array();
- var sum = 0;
- var i;
- for(i = 0; i < 208; i++)
- {
- stat[i] = 0;
- }
- for(i = 0; i < text.length; i++)
- {
- if((text.charCodeAt(i) >= 0x400 && text.charCodeAt(i) <= 0x44F))
- {
- stat[text.charCodeAt(i) - 0x400]++;
- sum++;
- }
- if((text.charCodeAt(i) >= 0x20 && text.charCodeAt(i) <= 0x7F))
- {
- stat[text.charCodeAt(i) + 0x50 - 0x20]++;
- sum++;
- }
- }
- if(sum > 0)
- {
- for(i = 0; i < 208; i++)
- {
- var prob = stat[i] / sum;
- if(prob > 0)
- result -= (prob * Math.log(prob));
- }
- result /= Math.log(2);
- }
- return result / 8 * 100;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement