D.9 Computations for Chapter 18

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.

The cards are represented by ten = 200514, etc., because t is the 20th letter, e is the 5th letter, and n is the 14th letter.

Type the following into Sage. The value of k forces the randomization to have 248 as its starting point, so the random choices of e and shuffle do not change when we repeat the process with this value of k. Varying k gives different results.

cards=[200514,10010311,1721050514,11091407,10305] 
p=24691313099 
k=248 set_random_seed(k) 
e=randint(10,10^7) 
def pow(list,ex): 
   ret = [] 
   for i in list: 
      ret.append(mod(i,p)^ex) 
   return ret 
s=pow(cards,2*e+1) 
shuffle(s) 
print(s)

Evaluation yields

[10426004161, 16230228497, 12470430058, 3576502017, 2676896936]

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.

Add the following line to the end of the program:

print(pow(s,mod(2*e+1,p-1)^(-1)))

and evaluate again:

[10426004161, 16230228497, 12470430058, 3576502017, 2676896936] 
[10010311, 200514, 11091407, 10305, 1721050514]

The first line is the shuffled and hidden cards. The second line removed the kth power and reveals the cards. The fourth card is the ace. Were you lucky?

If you change the value of k, you can play again, but let’s figure out how to cheat. Remove the last line of the program that you just added and replace it with

pow(s,(p-1)/2)

When the program is evaluated, we obtain

[10426004161, 16230228497, 12470430058, 3576502017, 2676896936] 
[1, 1, 1, 24691313098, 1]

Why does this tell us the ace is in the fourth position? Read the part on “How to Cheat” in Section 18.2. Raise the numbers for the cards to the (p1)/2 power mod p (you can put this extra line at the end of the program and ignore the previous output):

print(pow(cards,(p-1)/2))
[1, 1, 1, 1, 24691313098]

We see that the prime p was chosen so that only the ace is a quadratic nonresidue mod p.

If you input another value of k and play the game again, you’ll have a similar situation, but with the cards in a different order.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.180.244