Here is a game you can play. It is essentially the simplified version of poker over the telephone from Section 18.2. There are five cards: ten, jack, queen, king, ace. They are shuffled and disguised by raising their numbers to a random exponent mod the prime 24691313099
. You are supposed to guess which one is the ace.
To start, pick a random exponent. We use the colon after khide()
so that we cannot cheat and see what value of is being used.
> k:= khide():
Now, shuffle the disguised cards (their numbers are raised to the th power mod and then randomly permuted):
> shuffle(k)
[14001090567, 16098641856, 23340023892, 20919427041, 7768690848]
These are the five cards. None looks like the ace that’s because their numbers have been raised to powers mod the prime. Make a guess anyway. Let’s see if you’re correct.
> reveal(%)
["ten", "ace", "queen", "jack", "king"]
Let’s play again:
> k:= khide():
> shuffle(k)
[13015921305, 14788966861, 23855418969, 22566749952, 8361552666]
Make your guess (note that the numbers are different because a different random exponent was used). Were you lucky?
> reveal(%)
["ten", "queen", "ace", "king", "jack"]
Perhaps you need some help. Let’s play one more time:
> k:= khide():
> shuffle(k)
[13471751030, 20108480083, 8636729758, 14735216549, 11884022059]
We now ask for advice:
> advise(%)
3
We are advised that the third card is the ace. Let’s see (recall that %% is used to refer to the next to last output):
> reveal(%%)
["jack", "ten", "ace", "queen", "king"]
How does this work? Read the part on “How to Cheat” in Section 18.2. Note that if we raise the numbers for the cards to the power mod we get
> map(x->x&((24691313099-1)/2) mod 24691313099,
[200514, 10010311, 1721050514, 11091407, 10305])
[1, 1, 1, 1, 24691313098]
Therefore, only the ace is a quadratic nonresidue mod