Uncategorized

Taking a password joke seriously

“I’m sorry but your password must contain 1 char each from: Arabic, Chinese, Thai, Korean, Klingon, Wingdings and an emoji”

This was a message from Finley Creative (@FinleyCreative) to Jeff Atwood (@codinghorror) on March 3, 2016. The original post seems to have gone away.

You could write a script to generate a password according to these rules. How secure would it be?

Multiplying the number of characters from each category gives

153 * 20992 * 57 * 11172 * 38 * 196 * 1409 = 21463556813227081728

possibilities. You could get different numbers depending on how you interpret each of the words in the rules. For example, the calculation above counts Arabic and Thai letters, but Klingon counts 26 letters, 10 digits and 3 punctuation marks.

Allowing the characters to appear in any order multiplies the number of possibilities by 7!  = 5040. This corresponds to 76.5 bits of entropy, about the same as 13 alphanumeric characters (upper and lower case).

You could generate a password as above, then using something like Base 58 encoding to turn into something you could type on a standard keyboard.

What if you wanted to use the seven Unicode characters as a password without converting them to ASCII characters first? This would be asking for trouble due to possible different encodings of the Unicode characters. Besides, sites that insist that your password contain a “symbol” can be quite restrictive in what symbols they allow.

Memorable 12-digit primes

There’s an old joke about having to enter a 12-digit prime number to continue using a program. I wrote about this years ago, on how to use Python to come up with a 12-digit prime. But suppose you do this often, and so you’d like memorize a 12-digit prime so you could enter it without having to run a Python script.

Here’s an easy one: 999999999989. The following code verifies that this number is prime.

>>> from sympy import isprime
>>> isprime(999999999989)
True

Major system encoding

Maybe that’s too easy, so you’d like to first find a 12-digit prime, then memorize it using the Major memory system.

>>> import random
>>> while True:
...     candidate = random.randint(10**11, 10**12 - 1)
...     if isprime(candidate):
...         print(candidate)
...         break
...
298412857819

To encode 298412857819, you might come up with “knob o’ fire, tin foil, cave tuba.” These things look ridiculous when written down, but they actually work, especially when you come up with them yourself: it’s hard to reuse someone else’s mnemonics.

Working backward

To come up with a mnemonic that looks reasonable in writing, you might approach the problem the other way around: generate memorable phrases until one happens to encode as a 12-digit prime. I asked Grok to do this, and it came up with “A young man sits near the lake” which decodes to 273201024157.

>>> isprime(273201024157)
True

I read a book on memory tricks one time, and the chapter on the Major system began by stating some ordinary sentence and the corresponding number, then asked which you’d rather memorize. This was highly misleading. The author came up with the mnemonic first then calculated the number.

Mnemonics in practice

In practice the number comes first: you construct a mnemonic for a number; you don’t start with a mnemonic and search for a number it fits. And you are far more likely to come up with nonsensical streams like “knob o’ fire, tin foil, cave tuba” than prose like “A young man sits near the lake.” The system works, with practice, but it doesn’t look like it would work when you write down the mnemonics. The fact that the series of words is nonsensical may help you form durable mental images.

If you try to remember “A young man sits near the lake” you have to remember a sequence of words, not a sequence of images. “A young man sits near the lake” and “A young man sitting near a lake” correspond to the same mental image, but they’re different sequences of words and decode to different numbers. A sequence of words might be easier to remember in the short term, but a sequence of vivid mental images sticks better over time.

To be fair, “knob o’ fire” is also fragile, since “o” could easily become “of”. But this goes back to what works in practice versus what looks like it would work in writing. I chose “knob o’ fire” because it looked better in writing than some other alternatives I came up with.

In practice people who use the Major system to remember words often use pegs, fixed encodings of sequences of digits, rather than improvising encodings. This eliminates ambiguities. For example, suppose one of your pegs is “rover” for 484 and you imagine a Mars rover. Then when recalling a number, there’s no ambiguity whether “Mars rover” should decode to 340 (for Mars) or 484 (for rover), assuming you have a different peg for 340, such as Morse code.

Finite hyperbolic planes

Euclid’s fifth postulate says that given a line ℓ and a point P not on ℓ , there is a unique line through P parallel to ℓ. In the projective plane there are no parallel lines, and in the hyperbolic plane there are at least two lines through P parallel to ℓ.

Recent posts have looked at finite projective and affine planes. This post will look at finite hyperbolic planes.

Finite projective planes come up far more often in application than finite hyperbolic planes. I’ve seen several resources on finite geometries that don’t mention the hyperbolic case. Finite hyperbolic geometries have less structure than their projective or affine counterparts and so are less useful.

The definition of a finite hyperbolic plane isn’t entirely standardized. We will use the following axioms for this post.

  1. Any two distinct points lie on exactly one line.
  2. Given a line ℓ and a point P not on ℓ, there exist at least two lines through P parallel to ℓ.
  3. There exist four points, no three collinear.
  4. Every line contains at least two points.

An example of a system satisfying these axioms is the complete graph of six vertices. The nodes are the points and the edges are the lines. In set-theoretic terms, the points are the one-element subsets of {1, 2, 3, 4, 5, 6} and the lines are all possible two-element subsets.

Complete graph K6

Note that lines in the finite hyperbolic plane are two element sets. The lines {5, 6} and {1, 3}, for example, are parallel because they do not intersect, even though the representations of {5, 6} and {1, 3} in the visualization above are not parallel in the Euclidean sense.

There are many other examples of system satisfying the hyperbolic plane axioms. Too many in some sense. You could say finite hyperbolic systems are less common in application because they are more common in count.

Discrete geometry posts

Where else to find me

This blog is the main place I write, but I also use other platforms, either to write new content or to announce blog posts.

X (née Twitter)

I have a several X accounts, one personal account (@JohnDCook) and several specialized accounts (@CompSciFact, @AlgebraFact, @DataSciFact, etc.). I announce new blog posts on the most relevant account.

RSS

You can subscribe to the blog via RSS and find out about each post as it’s published.

RSS was very popular before Google killed its RSS reader, but it still works just fine. I use RSS to subscribe to the blogs I read.

The hard part of using RSS is finding a reader you like. I use Inoreader. I’m sure an LLM could help you find an RSS reader for your preferences and help you get started using it.

Mathstodon & Bluesky

I announce my math-related posts on Mathstodon at mathstodon.xyz/@johndcook. I also use a service that repeats my Mathstodon posts to Bluesky at johndcook.mathstodon.xyz.ap.brid.gy.

I don’t know why, but more people have started following me on Mathstodon over the last couple weeks.

Substack

Some people like to get email notifications of posts. I used two or three services that sent out such emails and they all stopped working. I tried out Substack and it has worked smoothly ever since.

My Substack newsletter has evolved into a bit more than just blog post announcements. I give a little intro to each post and some additional info such as how a sequence of posts are related or ideas that occurred to me after writing the post.

LinkedIn

Once in a while I post something to LinkedIn. If you’d like to know more about my background, you can see my profile there.

Backdoors, Incompetence, and Elliptic Curves

The NIST elliptic curves have been in the news twice lately. A few days ago Anthropic posted a paper on the NIST curve seeds that I wrote about here. Now the curves are in the news again, this time over broken certificates.

My post a few days ago was about the possibility that the NSA had added a backdoor to the NIST curves. Anthropic researchers showed that this wasn’t the case. The NSA had not been able to defend how the curve seeds were chosen because they forgot, but researchers from Anthropic were able to reverse engineer the source of the seeds.

So apparently the NIST curves do not have a backdoor, but as with all encryption, the Achilles heel is human error. eMudrha was using the NIST curve P-384  with extremely small keys: 4, 56, 115, 155, 156, 230, and 237. To understand why this is a problem, I’ll briefly describe how elliptic curve cryptography works.

P-384 is an elliptic curve designed by NIST, with input from the NSA, for use in cryptography. The curve has on the order of 2384 points because the base field is the integers mod

p = 2384 − 2128 − 296 + 232 − 1,

a 384-bit prime number. Given a basepoint b on the curve and an exponent e, it is practically impossible to recover e from be. That’s the discrete logarithm problem [1], the basis for the security of elliptic curve cryptography. If and when cryptographically relevant quantum computers arrive, the discrete logarithm problem will be solvable and elliptic curve cryptography will be broken.

Until the advent of quantum computing, elliptic curve cryptography is presumably safe, unless someone does something negligent, such as using a tiny value of e like 4.

If e is chosen at random from a group with on the order of 2384 elements, you cannot recover e from be without brute force. But apparently someone said

Let’s see. Is e = 1? Is it 2? Is it 3? Is it 4? Why yes: e = 4.

Ordinarily this would be hopeless. You can’t just try 2384 exponents. But someone thought to test whether the keys were horrifically bad, and they were right.

 

[1] The exponentiation here is not over the integers, or over the integers mod p. It’s over the group structure of the elliptic curve, and that is what makes it hard to compute the discrete logarithm.

Deliberate imperfection

I was watching a video by John Higgins this morning about the poem in Ecclesiastes 3, one of the most famous passages in the Bible.

There is a time for everything,
and a season for every activity under the heavens:

a time to be born and a time to die,
a time to plant and a time to uproot,
a time to kill and a time to heal,
a time to tear down and a time to build,
a time to weep and a time to laugh,
a time to mourn and a time to dance,
a time to scatter stones and a time to gather them,
a time to embrace and a time to refrain from embracing,
a time to search and a time to give up,
a time to keep and a time to throw away,
a time to tear and a time to mend,
a time to be silent and a time to speak,
a time to love and a time to hate,
a time for war and a time for peace.

The poem has a great deal of symmetry, from birth and death to war and peace. It has seven couplets, and the number seven in the Bible is symbolic of perfection.

There is a repeated pattern of groups of four words: a time for X, a time for Y. The rhythm reminds me of Beethoven’s fifth symphony, especially the third movement [1].

Higgins points out that there’s something odd in the middle couplet:

a time to scatter stones and a time to gather them,
a time to embrace and a time to refrain from embracing,

It breaks the rhythm, at least in English translation, and presumably in the original language. The poem goes from intransitive adjectival infinitives —to plant, to uproot, etc.—to transitive—to gather stones. Also, the two parts of the couplet do not obviously fit together. There’s a similarity between birth and planting, between killing and tearing down, etc. But what’s the connection between casting stones and embracing?

Higgins explains that this deliberate symmetry breaking fits the theme of the Ecclesiastes as a whole. There is order to the world, and yet we don’t have it all figured out. Even when everything mostly makes sense, there’s something we don’t understand, like the middle couplet.

[1] This has been called the fate motif. There is an apocryphal story that Beethoven described it as such to his secretary and biographer Anton Schindler. Regardless of whether the story is true, the name stuck. Here’s the particular part I had in mind.

Sheet music for Beethoven: Symphony No. 5, Op. 67. Third Movement Horn Theme

Refactoring factorials

Splitting N! into N factors is trivial. It’s defined as the product of N integers, the integers 1 through N.

Can you still split N! into N factors if you put a minimum size requirement on the factors?

You can’t split 3! into three factors unless one of the factors is 1, but you can split 4! into factors ≥ 2:

4! = 24 = 2 × 2 × 2 × 3

Define t(N) as the largest number such that N! can be expressed as the product of integers greater than or equal to t(N). So based on the discussion above, t(N) ≥ 1 for all N, t(3) = 1 and t(4) = 2. The t(N) are given in OEIS sequence A034258.

Last Thursday an article came out proving an asymptotic estimate for t(N). You can find a preprint on arXiv.

An upper bound on t(N) would be the Nth root of N! because that would correspond to splitting N! into N factors of equal size. But the Nth root of N! will not be an integer for N > 1, so the bound would not be tight.

If we apply Stirling’s approximation for factorial we get

t(N) / N ≤ 1/e + O(log(N) / N).

It was conjectured that for large N

t(N) / N ∼ 1/e − c0 / log(N)

and the new paper proves

t(N) / N ∼ 1/e − c0 / log(N) + O(1 / log1 + c N).

.

Cloud of suspicion lifted from NIST curves

NIST published a set of elliptic curves for cryptography in 2000. The seeds for the curves were supplied by the NSA, and cryptographers suspected the agency may have installed backdoors in the curves. And not without reason: the NSA did insert a backdoor in the Dual_EC_DRBG random number generator.

Two days ago researchers at Anthropic [1] showed that the NIST curves were not seeded with a backdoor. The rest of this post will give the background necessary to appreciate this result.


The security of elliptic curve cryptography depends on the difficult of solving the discrete logarithm problem. In the context of elliptic curve arithmetic, the analog of exponentiation is easy but the analog of taking logarithms is hard.

In general it’s not practical to compute discrete logarithms over large elliptic curves. But it could be easy for someone with inside information to compute discrete logarithms if something about the curve was not “general.”

Specifically, the NIST curves have the form

y² = x³ − 3x + b (mod p)

for various values of p [2], and the suspicion regards the choice of b. For nearly all values of b encryption over the elliptic curve should be secure, as far as we know, but in principle someone could engineer values of b to weaken the encryption.

So where did the b‘s come from? Were they chosen in good faith?

Concern over the choice of seeds, the b‘s, grew following the Snowden revelations. Daniel J. Bernstein emailed Jerry Solinas of the NSA on September 6, 2014 asking where the seeds had come from. Solinas replied in subsequent emails. He said the seeds were generated by hashing the ASCII representation of a humorous English message, but he could no longer remember the exact message or the precise hashing procedure.

On October 5, 2023 Philippo Valsorda announced a bounty for reverse engineering the origin of the NIST elliptic curve seeds. Two days ago researchers from Anthropic claimed the bounty. Valsorda verified the results and awarded the prize. It turns out Solinas found the curve seeds in good faith, but his memory had faded over the years since the curves were published. We now know he used a date, not a phrase, as part of the process of constructing the seeds.

The NIST curves have some nice properties, such as enabling some clever tricks for arithmetic in their base fields. But adoption of the curves has been held back over suspicion regarding their origin. Now the curves have been exonerated. As Valdorda notes

… this nicely completes the “rehabilitation arc” of NIST elliptic curve cryptography, which I would now personally recommend over Curve25519/Ed25519/X25519. Just in time for them to be retired in favor of post-quantum signatures.

Related posts

[1] This does not imply that LLMs are necessarily a threat to encryption. The search for the NIST seeds required a lot of brute force. Some cleverness was required in order to come up with possibilities to check by brute force, but even that is sorta brute force at a higher level of abstraction. There has been speculation that labs are looking for weaknesses in cryptographic primitives and protocols, but that’s a different matter than searching for seeds.

[2] The curves P-192, P-224, P-256, P-384, and P-521 are built over the field of integers mod p, where the number of bits in p corresponds to the number in the name. The P-192 curve, for example, has as its base field the integers mod 2192 − 264 − 1, a 192-bit prime.

Privacy policies and modal logic

If you’ve followed this blog for a while, you may know that I do a lot of work with data privacy and that I have an interest in modal logic. Recently these two worlds collided: I became aware of work that uses modal logic to reason about data privacy.

The story begins with Helen Nissenbaum’s paper Privacy as Contextual Integrity [1]. Rather than simply classifying data as public or private, Nissenbaum looks at norms around the context in which data exists and moves.

… the benchmark of privacy is contextual integrity; that in any given situation, a complaint that privacy has been violated is sound in the event that one or the other types of the informational norms has been transgressed.

A couple years later Nissenbaum coauthored a paper [2] with three Stanford computer scientists using modal logic, specifically linear temporal logic (LTL), to reason about contextual integrity. The paper uses four modal operators: the usual box and diamond, plus past tense versions with a minus sign across the middle.

box, diamond, box minus, diamond minus

These four operators can be read as “henceforth”, “eventually”, “historically”, and “once.”

Henceforth means something will always be true into the future; historically means something was always true in the past.

Eventually means something will happen at some time in the future; once means something occurred at some time in the past.

You could imagine using these operators to formalize statements such as data sharing in some context is permissible (henceforth) if the data subject has (once) signed a consent form.

Understanding simple stand-alone policies does not require the machinery of formal logic, but analyzing large collections of interacting policies may. It may be, for example, that a collection of policies cannot all be satisfied, though this is not obvious from looking at the individual policies. Formalizing policies in the language modal logic makes their analysis amenable to well established algorithms.

Related posts

[1] H. Nissenbaum. Privacy as contextual integrity. Washington Law Review, 79(1):119–158, 2004.

[2] A. Barth, A. Datta, J. C. Mitchell, and H. Nissenbaum, “Privacy and contextual integrity: Framework and applications,” in Proc. 2006 IEEE Symp. Security and Privacy (S&P’06), Berkeley/Oakland, CA, USA, 2006, pp. 184–198, doi: 10.1109/SP.2006.32.

Topological models of modal logic

The previous post discussed a superficial connection between modal logic and topology, that both use the terms regular and normal to indicate added sets of axioms. McKinsey and Tarski developed a deeper connection between modal logic and topology that we’ll discuss here.

Starting with a topological space X and a proposition p, define [[p]] as the set of points in X at which p is true. Define □p to be true at points in the interior of [[p]] and define ◇p to be true on the closure of [[p]].

You could think of □p as the points where p is robustly true. Not only is p true at x, there’s some wiggle room around x, i.e. an open set, in which p remains true.

You could think of ◇p as the points where we cannot rule out the possibility of p being true using open sets. If ◇p includes x, any open set containing x also contains part of ◇p, though it may also contain points outside of ◇p.

Regularity

For any topology on X, the logic constructed above is normal. The axiom

\Diamond p \Leftrightarrow \lnot (\Box \lnot p)

holds because the closure of a set is the complement of the interior of its complement [1].

Note that this is a regularity result for the modal logic, not the topology. The topology could be arbitrary, and not necessarily regular or normal in the topological sense.

S4

The logic constructed above also satisfies a couple more axioms. We have

\Box p \to p

because the interior of a set is a subset of the set, and

\Box p \to \Box\Box p

because the interior of the interior of a set is simply the interior. This means the modal logic corresponding to a topology satisfies the S4 axioms. You could say S4 is the logic that corresponds to the McKinsey and Tarski logic of all topological spaces.

More logics and more topologies

So S4 is the logic that corresponds to all topologies. We could look at more restricted topologies and ask what are their corresponding logics. Or we could start with a modal logic and ask whether there’s a topology that models that logic.

Interesting logics correspond to badly behaved topological spaces. Familiar topological spaces like the real line correspond to S4.

Trivial modal logic

The discrete topology corresponds to the trivial modal logic. All sets are open, and closed, so any set is the same as its interior and its closure. So □p and ◇p reduce to just p.

S5

For the indiscrete topology, □p corresponds to a proposition holding everywhere and ◇p corresponds to it holding somewhere. If the topological space has infinitely many points, the corresponding modal logic is S5. [2]

Between S4 and S5

The cofinite topology on an infinite set X defines a set U to be open if the complement of U is finite. The McKinsey-Tarski logic of the cofinite topology is somewhere between S4 and S5. You can show that the formula

p \land \Diamond\Box p \to \Box p

holds, which doesn’t hold in S4, and the formula

\Diamond p \to \Box\Diamond p

does not hold, though it must hold in S5.

Related posts

[1] We should also verify that if A ∩ B ⊂ C, then Interior(A) ∩ Interior(B) ⊂ Interior(C).

[2] Propositions can only have a finite number of terms. Having infinite points in the topological space prevents the corresponding logic from proving theorems that don’t necessarily hold in S5.