Cryptography
Cryptography is the study of codes. The basic idea is that we have a message we want to send to a friend. However, we don't want anyone but the our friend to see our message. So we hide it via some clever method.
Shifty business
Let's do some cryptography. Enter a message in the text box below, then use the slider to encrypt it! This is an example of a Caesar cipher, where we take a message and shift all the letters to the left or right by a fixed amount (for example a shift by 1 would send to , to etc.).
Example
Can you create a secret message and pass it to the person next to you to decode?
Try to intercept someone elses message and decoding it.
Passphrase plz
A slightly better cryptosystem is the Vigenere cipher. This uses system uses a passphrase as the key. The pass phrase tells us how much to shift each letter by. For example if the passphrase is ABC
then we shift the first letter by , the second letter by , and the third letter by . If there are still more letters, than we simply repeat. The next letter will be shifted by , the one following by , and so on.
Example
This system is also already in Sage, so we can run pretty much the same application as before.
Subs
The next crypto system we could try is a substitution cipher. This substitutes letters via a predetermined map.
For example, suppose we declare the key to be , , , and all other letters remain the same.
What is the encryption of hello there
?
Example
Sage makes it easy to try out substitution ciphers.
A modern approach
An example of a more modern cryptosystem is R.S.A. which stands for Rivest, Shamir and Adleman. The reason why RSA works well is because it is based off the problem of factoring. Factoring is easy to understand but hard to solve efficiently on a computer.
Recall factoring means finding the prime factors. For example factors into . The factorization of is just because it is already prime.
Side note:
The public keys used in RSA are of a very special form. They are always of the form for two large primes and .
Example
Evaluate the following cell to see how Sage factors integers.
Lag?
Did you notice a slight pause? That is because factoring an integer can be very difficult. To see this, try to find a factor of It probably didn't take you too long to notice that divides this number because it is even (notice the last digit).
To see how much easier it is to factor this number, try factoring it in sage below.
Form matters!
Did you notice how much faster it was? The numbers used in RSA are of a special form. They are always the product of two large primes, i.e. for some primes and . The is sometimes referred to as the modulus. The special form makes factoring take longer. In the following we will mostly consider numbers of this form.
A first try
Let's say we have a number . If we want to find a factor of , one thing you might try is testing if a smaller number divides . So you check: Does divide ? Does divide ? Does divide ? ...
This will eventually find a factor. In fact, you will have to try at most different numbers (can you see why?). So this method will factor in about steps.
I live at 45-45
What is the maximum number of steps it take to factor a number with digits?
A number with digits is at least as large as (notice is the smallest number with digits, is the smallest number with digits, ...)
So factoring should take at least number of steps.
Till the end of the universe
How long would it take a computer to do this? Remember computers are fast. A modern day PC processor runs at about gigahertz, or about operations per second. So a fast computer could perform one of our steps in about seconds (I added a zero).
So steps at seconds each is a total of seconds.
How long is this? We can have Sage convert the units. Make sure to take a guess before evaluating the next cell!
Same but with a picture
We can also plot the same information in Sage. Note that this plot represents the time it would take our niave algorithm to factor an integer with some number of digits.
But we just did this...
So you might notice we just factored a digit number with Sage earlier in a few seconds. This is because Sage uses a very clever algorithm to factor large numbers.
Currently, the fastest algorithm for large numbers (over digits) is the number field sieve. It's much faster than our method above.
In the real world
Common implementations of RSA use key sizes of bits. This means the modulus is about , i.e. bits, or equivalently about digits.
##!!!WARNING!!!
We have NOT made a claim about security. The larger the key size generally means the more computational resources it will take to factor. However, with the computational power of the cloud and giant clusters of computers, some numbers are within reach of direct factorizing.
###A recent crisis
Web security commonly uses RSA encryption to keep your credit cards and personal information safe when you send it to stores and buisnesses over the internet. You can even see what kind of encryption a particular site is using from your browser. Most web servers will use key sizes from to bits. However, a recent security bug named "FREAK" allowed adverseries to downgrade to a very insecure bit key.
An RSA modulus of bits was factored in 1999. It took months with advanced hardware at the time. In 2015, with relatively small cost (probably less than ) you can have a cluster of computers in the cloud factor a bit modulus in less than a day.
For more on the current state of factoring, see RSA Factoring Challenge
Beyond factoring
Often RSA keys are broken through methods besides factoring. Suppose two people have RSA keys given by and
Normally these would be hard to factor. But there was a mistake in generating these keys. Remember all RSA moduli are the product of two primes. These keys happen to share a prime. Since we can compute the greatest common divisor very quickly, we can quickly break both keys: