## A magazine where the digital world meets the real world.

# On the web

- Home
- Browse by date
- Browse by topic
- Enter the maze
- Follow our blog
- Follow us on Twitter
- Resources for teachers
- Subscribe

# In print

# What is cs4fn?

- About us
- Contact us
- Partners
- Privacy and cookies
- Copyright and contributions
- Links to other fun sites
- Complete our questionnaire, give us feedback

# Search:

# Magic Through the Trapdoor

*
You take a deck of cards, shuffled by a spectator, and deal them into
two piles. Three cards are selected from one pile, and placed face up.
Various face down cards are dealt on to these face up cards. You use the
values and suits of the three face up cards to correctly predict a card
and its position in the face down pile. If your spectator tries to
repeat your amazing feat they fail. It's a trick that can't be
explained!
*

# How it's done

## A note to the professor

This is a simplified take on the classic effect by magician Dai Vernon: "The Trick That Can't Be Explained". The trick presented here uses some of the brilliant ideas that Dai used, but if you are interested in the magic, rather than just the computing part, then you should study the original effect.

## The works

So how do you carry out the card miracle described above? First things first. You need to ensure it's a full pack of 52 cards, no jokers. The pack can be shuffled by a spectator and when you get it back you need to split it in half into two piles of 26 cards, and be sure you get a glimpse of and memorise the seventh card in one of the piles - this is your target card.

## Acquiring your target

The easiest way to do this is to count 26 cards from the pack face up on the table, remembering the seventh card you deal. Don't break the count when you reach 7 though or you will give it away. You might explain the face up dealing as 'look all the cards are shuffled'. Take the face up pile of 26 cards (7th memorised) and turn face down. For the other cards you can deal the remaining 26 face up and then turn them over or just assume there are 26 and keep them face down.

## Top to 10

Take the pile without the memorised card in it and deal three cards from it face up. You can do this either straight from the top of the pile, or get the spectator to choose them. You now have three face up cards on the table. Next deal face down cards onto these, just above them so that the total comes to 10: Jacks, Queens and Kings count as ten already. So if the card is a 2 then you deal 8 face down cards on top. If it's a Queen you deal none.

After doing this for all three cards, place the remainder of this pack face down on the unused pile of 26 (with the memorised 7th). Now add together the values of the three face up cards and announce your prediction (the memorized card). Count that number of cards down into the unused face down pack and reveal you were right!

If you have done things in the right way, you have ensured that when you count down that number of cards on the unused face down pack you will come to your memorised card which is also your prediction.

## Reusing code

The trick works mathematically using an algorithm that we described in a previous trick, so if you want to know why adding those three cards together and counting down gets you to your target card then go read 3,2,1 Blast Off. Computer coders often reuse bits of code and this trick does the same thing. It reuses these ideas, the same basic algorithm, but in a different setting. But this trick is different. In the blast-off trick we predict the target card in advance and can write it on a bit of paper well in advance, here we are working impromptu with a shuffled deck so although the maths says that if we total the values of the face up cards and count down in the unused pile then we will find the target card, how do we make the magic work and do the prediction in real time?

## Create your trapdoor

This is where you need to get creative in your performance. For example, suppose the memorised target card is the seven of spades, and the three face up cards are the 6 of Clubs, the 2 of Diamonds and the Queen of Hearts. That means that we know the target will be 6+2+10=18 cards down in the pile, but how do we explain our prediction of its actual value, the name of the card? The answer is you make up some seemingly rational explanation on the fly based on the situation. You explain how you will use the arcane skill of reading the cards (it's easier than tea leaves!) to make the prediction.

For starters, you can just state that adding the cards will give its position as 18 cards down. You could then explain that, in this case, it will be a Spade because "Spades is the only card suit not shown in the face up 'indicator' cards". Your story could then continue that it must also be a 7 because "a 6 and a 2 give 8, but there is only one royal card, so we subtract 1 to give 7." Put together "That means the card will be the seven of spades!"

Given that you know your target, some sort of explanation will arise, whether simple or complex. If things get sticky perhaps you can turn over the top card on the face down pile, that gives you more wriggle room (just remember to turn it back before doing the count). Remember card's names can be used as numbers. A KING could act as a 4 in trying to reveal the name of the target card for example. You could also use the fact that a diamond has four points, a club has three bumps, a heart has two and a spade has one. The indicator card's position could also be 'important' in determining the card. Use your imagination!

## Confidence and 'clarity'

Imagination and confidence in presentation will convince your spectator there is only one way that the indicator cards could be pointing and that's to the target card. You're only going to do the trick once for them after all, so what you say must be the rules. Of course if they were to try it themselves it would be impossible to repeat. First they don't know what you know, that is the target card name, and secondly if they apply your seemingly complex formula to the indicator cards they will get nonsense. This can be fun to watch, especially if you don't over stress the importance of adding the indicator card values together to make the trick work and concentrate more on the flim-flam stuff.

## What's all this to do with computing?

An obvious link is that you have used an algorithm that always gives the desired effect to ensure that the indicator card total will always find the target card in the face down pile. On top of that though this trick includes a lovely example of the creation of what's known as a trapdoor function. A trapdoor is easy to pass through in one direction, but once you have its hard to get back. Similarly, a trapdoor function is a mathematical formula that is easy to compute in one direction - you can apply it to the data you have and get an answer. However it is difficult to compute in the opposite direction, getting the original data from the answer (the inverse) without knowing extra secret information. It's computationally hard when you try to go backwards.

A simple example involves using modular or clock arithmetic. Suppose I take the number 27 and apply the formula of repeatedly dividing it by 10 leaving the remainder, then give you only that answer - the number 7. Even if you know the formula, you don't know if my original number was 7, 17, 27 37, etc. Trapdoor functions like this are used a lot in cryptography and as a way to create digital signatures. They are a method for people to 'sign' documents in a way others can be sure only they could have done it. Just because someone has one of your digital signatures, you don't want them to be able to work out from it your secret key as that would allow them to forge your signature themselves.

In a similar way in the trick, you can't go back from the answer to know the secret that allows the trick to be repeated. Even when you have the answer, (i.e. the target card name and location) you can't reverse the trick and extract the secret part of the method, (i.e. the need to memorise the 7th card of the pack) which here is the way the magician actually predicts the card.

## Try it!

Practice the trick a few times first and think through the strategies you can use to come up with enough wriggle room to be able to state the target card name. Once you're happy with this, perform it a few times. If you enjoy it perhaps then perhaps give Dia's version a go. Learning magic can be as much fun as learning computing.