Search for a tool
Shannon Index

Tool to calculate the Shannon index. The Shannon index is a measure of entropy for characters strings (or any computer data)

Results

Shannon Index -

Tag(s) : Informatics, Cryptanalysis

Share dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Thanks to your feedback and relevant comments, dCode has developed the best 'Shannon Index' tool, so feel free to write! Thank you!

# Shannon Index

## Shannon Index Calculator

### What is Shannon's Entropy Index (Definition)

Shannon's entropy index, as the name suggests, is a measure of the entropy that applies to any numerical data. It measures the frequencies of appearance of the characters, and the more they are different, the more difficult it will be to predict the content (thus a greater uncertainty, and thus a greater entropy).

### How to calculate Shannon's Entropy? (Formula)

For a string of characters with $n$ distinct characters, each character having a frequency of $p$. The entropy of Shannon $H$ is calculated according to the formula $$H = -\sum_{i=1}^n p_i \log_2 p_i$$

Example: DCODE has 5 characters including 4 distinct characters, the letter D appears 2 times (frequency: 2/5), and the 3 letters C, O and E each appear 1 time (frequency: 1/5), the calculation is: $H = -\left( \frac{2}{5} \log_2{\frac{2}{5}} + 3 \times \frac{1}{5} \log_2{\frac{1}{5}} \right) \approx 1.921928$

The value is always positive, the logarithms of numbers less than 1 are always negative, their sum too, the sign - makes it possible to obtain a positive result.

### What is the Shannon index for?

From the Shannon index, the optimal encoding of a string can be deduced. If the Shannon index of a string is 3.5, then it will take 4 bits (rounded up) by characters to encode it optimally. The Shannon index can then be useful for evaluating a compression ratio, the higher the entropy, the better the compression.

## Source code

dCode retains ownership of the online 'Shannon Index' tool source code. Except explicit open source licence (indicated CC / Creative Commons / free), any 'Shannon Index' algorithm, applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any 'Shannon Index' function (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) and no data download, script, copy-paste, or API access for 'Shannon Index' will be for free, same for offline use on PC, tablet, iPhone or Android ! dCode is free and online.

## Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!