Questions tagged [entropy]

Entropy is a measure of how predictable the outcome of a random process is, or how much uncertainty one has about an unknown quantity in one's state of knowledge, defined in terms of the probability distribution on possible outcomes or quantities.

Entropy is a property of a probability distribution on the set of possible values of a random process or of an unknown quantity. A probability distribution $P$ quantifies the plausibility of each possible value $x_1,$ $x_2,$ $\dotsc,$ $x_n$ by assigning it a numerical probability $P(x_1),$ $P(x_2),$ $\dotsc,$ $P(x_n)$ between $0$ and $1$; the entropy of $P$ is a single measure loosely summarizing the magnitude of uncertainty about what value the random process might yield, or the unknown quantity might actually be.

The two most common kinds of entropy are:

  • Shannon entropy, $H(P) := -\sum_i P(x_i) \log_2 P(x_i)$, is the average number of bits per sample that an optimal compression algorithm tuned for the distribution $P$ can compress random samples from $P$ into.

    Shannon entropy, named after Claude Shannon for his seminal work on information theory, is most often what unqualified ‘entropy’ refers to outside cryptography in information theory and coding theory. Shannon entropy is useful for estimating the average cost of transmitting samples of $P$ by telegrams that you must pay for by the bit.

  • Min-entropy, $H_\infty(P) := -\log \max_i \log_2 P(x_i)$, is the number of fair coin tosses that all come up heads with the same probability as the best strategy of guessing a sample from $P$ on the first try.

    Min-entropy is the number of fair coin tosses coming up heads that the best guess for a single outcome has the same probability as, and is most often what unqualified ‘entropy’ refers to in cryptography. Min-entropy is useful for estimating an adversary's probability of success at guessing a key in a single trial.

Example. A four-sided die with probability 1/2 of turning up 1, probability 1/4 of turning up 2, and equal probabilities 1/8 of turning up 3 or 4, can be compressed into messages, say for transmission by telegram which costs by the bit, as follows:

  • Transmit the face 1 as a 0 bit.
  • Transmit 2 as the bit string 10.
  • Transmit 3 as 110.
  • Transmit 4 as 111.

The most probable outcome, rolling a 1, has the same probability as a single fair coin toss coming up heads, 1/2. Thus the min-entropy is 1 bit.

The average number of bits per sample in this compression scheme is the sum of each number of bits weighted by its probability. A straightforward calculation shows that this compression scheme is optimal, because the average number of bits coincides with the Shannon entropy, namely 1.75 bits.

This example illustrates a theorem the min-entropy is never greater than the Shannon entropy; that is, Shannon entropy is an upper bound on min-entropy, so it is useful in cryptography as a limit on the best min-entropy you can hope for from a physical system.

Rényi entropy is a generalization that covers both Shannon entropy and min-entropy as instances, but it seldom figures into cryptography. Entropy can be measured in other units such as nats, decibans, etc., if computed with base-e, base-10, etc., logarithms instead of base-2 logarithms, but this is seldom seen in cryptography.


Thermodynamic entropy is related to Shannon entropy. In a thermodynamic system characterized by macroscopic averages such as temperature, pressure, volume, etc., the (thermodynamic) entropy change of the system is defined in terms of the macroscopic heat transfer into or out of it and its temperature change.

A priori, this concept of classical thermodynamics may not be obviously related to information theory or probability distributions, but turns out to have an interpretation in terms of the Shannon entropy of a family of probability distributions.

In the microscopic formulation of statistical mechanics, when a thermodynamic system is described in terms of macroscopic averages, there are many possible microscopic configurations that the system could be in that are compatible with the macroscopic averages. Among the probability distributions on microscopic configurations compatible with the macroscopic averages, the maximum Shannon entropy of any such probability distribution is the (thermodynamic) absolute entropy of the system (with an appropriate choice of logarithm base to make the units commensurate), and a change in entropy coincides with a difference of absolute entropies.

Historically, the term entropy was invented by Rudolf Clausius as a macroscopic property of a thermodynamic system, before Ludwig Boltzmann connected it to microscopic configurations in his H theorem and J. Willard Gibbs expounded on it in the development of statistical mechanics. Claude Shannon later stumbled upon the same formula as Gibbs, but from the perspective of channel coding and information theory. Inspired by Boltzmann and Gibbs, Shannon adopted the name ‘entropy’ and letter H for the property of any probability distribution.

409 questions
118
votes
4 answers

How should I calculate the entropy of a password?

If part of the password is a whole regular English word, does the entropy of that part depend on the number of English words in existence, the number of English words known by the choosing algorithm, the number of English words assumed by the…
this.josh
  • 2,037
  • 4
  • 17
  • 13
46
votes
2 answers

What is entropy?

We discuss a lot of topics and use measures of entropy to determine how difficult it is for an attacker to be successful. What does entropy mean in the context of cryptography? How is entropy calculated in the general case?
this.josh
  • 2,037
  • 4
  • 17
  • 13
35
votes
1 answer

Should I use the first or last bits from a SHA-256 hash?

I have the need for a hexadecimal token that is smaller than the normal length of the hexadecimal representation of a SHA-256 hash. Should I take the first bits or the last bits? Which of them contain the most entropy?
Peter Smit
  • 453
  • 5
  • 7
28
votes
5 answers

Could RDRAND (Intel) compromise entropy?

I was recently discussing the issue of RDRAND in Intel chips and the whole issue about how NSA could potentially be influencing Intel to weaken or create backdoors in their design. This petition was posted asking Linus Torvalds to ignore RDRAND and…
Michael Aquilina
  • 880
  • 1
  • 8
  • 11
26
votes
3 answers

How is the One Time Pad (OTP) perfectly secure?

The Wikipedia entry on One Time Pads (OTPs) states that if this cipher is used properly; ie, the keys are truly random and each part of the key is independent of every other part, it's uncrackable, and yields perfect secrecy, i.e., $H(M|C) =…
xyz
  • 465
  • 1
  • 5
  • 9
26
votes
2 answers

If you hashed a hash an infinite number of times would you end up with a unique hash?

If you took a hashing algorithm for example MD5 and repeatedly passed the output hash back into the algorithm an arbitrarily large number of times would you eventually end up with one unique hash? My idea is that the maximum number of hashes…
AceLewis
  • 363
  • 3
  • 7
24
votes
2 answers

Can Shannon's entropy be used to determine if a file is encrypted?

If we have to determine a file is encrypted or not, can we use Shannon's entropy algorithm on the file? As discussed here, the entropy (in bits per byte) being closer to 0 is considered as more orderly and being closer to 8 is considered more…
sashank
  • 6,234
  • 4
  • 36
  • 68
20
votes
8 answers

Password cracking: What if attacker is lucky?

We have always measured password or private key strength by the amount of entropy it contains, but what if the attacker who cracks it is lucky. Consider the following simple scenario, we have 1 bit [0,1] secret , the attacker should choose between 2…
cryptonoob400
  • 553
  • 1
  • 5
  • 12
19
votes
2 answers

A website that identifies an RNG from its output

This happened during a discussion of RNG entropy, and the difficulty of verifying the level of entropy in a long sequence of bits (e.g. a private key.) A colleague of mine told me about a website that, given a sufficient quantity of output from an…
19
votes
1 answer

Where do Windows applications get entropy from?

Where does the entropy that cryptographic .NET libraries use for encryption come from? I know with Linux you can use /dev/random, but does a similar pool exist within Windows?
Verbal Kint
  • 289
  • 2
  • 5
19
votes
3 answers

Why do "nothing up my sleeve numbers" have low entropy?

As a preface, forgive me for some of the links being from Wikipedia. I realize that academia frowns upon this. I came across this article about "nothing up my sleeve numbers". In it, it says: In cryptography, nothing up my sleeve numbers are any…
asteri
  • 293
  • 1
  • 5
17
votes
1 answer

What to watch for with openssl generating weak keys? (low entropy)

(Disclaimer: I am regular software engineer with only basic crypto knowledge, so helpful if can be explained for a layman.) I am concerned about generating weak keys on a shared linux box with openssl. Some questions: How low does entropy have to…
17
votes
4 answers

How is the quality of a password calculated and what does it mean?

While using Keepass and using it to generate random passwords, I always have noticed the "quality" section but truthfully have never known what it actually means. So my questions are; How much entropy is enough? How much is overkill? How does…
Shackrock
  • 273
  • 2
  • 6
17
votes
5 answers

Examples of frauds discovered because someone tried to mimic a random sequence

[Moderator note: this question now lives there] So, I'm preparing a talk about the well known fact that humans are bad at the task of generating uniformly random sequences of numbers when asked to do so, which is a huge flaw for simple cryptographic…
15
votes
2 answers

Calculating entropy within xkcd 936: Password Strength

When I calculate entropy for the xkcd Password Strength (comic 936) I don't get nearly the amount of entropy stated in the comic. So why doesn't the the first password "Tr0ub4dor&3" have an entropy of around 50 bits? And why doesn't the passphrase…
Blafasel
  • 163
  • 1
  • 5
1
2 3
27 28