How to calculate the entropy of a file?

前端 未结 11 1325
野趣味
野趣味 2020-11-28 20:16

How to calculate the entropy of a file? (Or let\'s just say a bunch of bytes)
I have an idea, but I\'m not sure that it\'s mathematically correct.

My id

11条回答
  •  再見小時候
    2020-11-28 20:41

    Is this something that ent could handle? (Or perhaps its not available on your platform.)

    $ dd if=/dev/urandom of=file bs=1024 count=10
    $ ent file
    Entropy = 7.983185 bits per byte.
    ...
    

    As a counter example, here is a file with no entropy.

    $ dd if=/dev/zero of=file bs=1024 count=10
    $ ent file
    Entropy = 0.000000 bits per byte.
    ...
    

提交回复
热议问题