Four Digit iPhone Passcodes
1. iPhone Passcodes
In this lesson, we will try to guess iPhone passcodes, and see how the probability of successfully guessing a passcode changes when the digits in the passcode are known.2. Unlocking an iPhone
iPhone users have the option of setting a required passcode, which on some iPhone versions is four digits in length. Any smudge marks left on the phone screen can suggest which numbers are in the passcode. For example, if a person's passcode is 2,5,7,6, the locations of those values on the screen might have smudge marks on them because of how often they have been pressed when unlocking the phone, giving a thief a huge insight into the passcode.3. Four digits vs. three digits
This lesson was inspired by Presh Talwalker, an author and creator of the mathematics blog called Mind Your Decisions. He noted that, perhaps counter-intuitively, if your four-digit passcode only has three distinct digits with one repeated digit, instead of four distinct digits, the probability of a thief successfully guessing your passcode based on the smudge marks on your screen is decreased. This puzzle could be solved using combinatorics, but let's learn to solve it using simulation. In this lesson, we will learn new ways to use the sample function and introduce the identical function.4. The sample function
Previously, we used the sample function in the roll underscore dice function and in the Monty Hall puzzle. Of the four arguments in the sample function, replace and prob have default values that will be used unless otherwise specified. For example, in the Monty Hall exercise, we chose one door, so size was set equal to one. We could leave replace at the default value of FALSE since we did not need replacement when sampling once. Although size does not have a default value shown, we can also leave size unspecified if we want to sample every value in the object in a random order. To do this, the only argument we need to provide is the object of interest, here, three underscore values. Note that we will leave the argument prob at the default value NULL, which indicates that each element of x has the same probability of being selected.5. Sampling from repeated values
We can also leverage the behavior of the sample function to help us guess passcodes that have one repeated digit. Consider this example in which we just have two distinct values. If we have a three digit passcode in which one of these is repeated, but we don't know which one, we can use the sample function to choose one at random. Here we create a new vector called all underscore values, which combines the original two values and selects one of those values at random. Then, to guess the order of these three values, we can use the sample function as in the previous slide.6. The identical function
Previously, we tested for equality using the double equal operator. This is straightforward for single values, or scalars, but for collections of values, or vectors, it will return a TRUE or FALSE for each element individually, which is not quite what we want. We would really like a single TRUE or FALSE indicating whether all values of the sets are equal or not. Rather than code a solution to this issue, it is easier to use the identical function, which will return a single TRUE or FALSE based on whether all values of the vectors are equal to each other, as shown here.7. Let's guess some iPhone passcodes!
Let's use these tools to guess some iPhone passcodes!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.