Introduction to Cryptography
Total Page:16
File Type:pdf, Size:1020Kb
Introduction to Cryptography Brian Veitch July 2, 2013 Contents 1 Introduction 3 1.1 Alice, Bob, and Eve . .3 1.2 Basic Terminology . .4 1.3 Brief History of Cryptography . .4 1.4 Kerckhoff's Principles of Cryptographic Secuity . 11 2 Substitution Cipher 13 2.1 Caesar Cipher Activity . 13 2.2 Keyword Cipher Activity . 17 2.3 Vigenere Cipher Activity . 20 3 Transposition 22 3.1 Easy Example . 22 3.2 Railfence Cipher . 22 3.3 Transposition Activity . 23 4 Modular Arithmetic 24 4.1 Examples of Congruences . 26 4.2 Arithmetic with Congruences . 27 4.3 Multipication Tables . 27 4.4 Finding the Inverse . 29 4.5 Solving Equations (mod n) . 32 4.6 The Extended Euclidean Algorithm . 34 1 CONTENTS 2 5 Diffie-Hellman Key Exhange 37 5.1 What is it? . 37 5.2 The Algorithm . 37 5.3 Example of a Key Exhange . 38 5.4 Why is Cracking this Exchange Difficult . 39 5.5 Key Exhange Activity . 40 6 RSA Encryption 42 6.1 Introduction . 42 6.2 Example of RSA Encryption . 42 6.3 RSA Algorithm . 45 6.4 Using The Extended Euclidean Algorithm . 46 6.5 ASCII Table . 50 6.6 Cracking RSA by finding the private key d.............. 52 6.7 Your turn to crack an RSA encrypted message . 53 7 Using RSA for Authentication 54 7.1 Algorithm . 54 7.2 Authentication Activity . 56 8 Important Information 57 8.1 Caesar Shift Wheel . 57 8.2 Letter Frequency Tables . 58 8.3 Vigenere's Table . 59 8.4 ASCII Table . 60 8.5 Useful Websites . 60 1 INTRODUCTION 3 1 Introduction You don't have to be an expert in cryptogrphy to appreciate the field. Cryptography is all around us. We use it to store senstive data, send secret messages, send financial information over the internet, hide messages from parents, etc. The methods we will cover in this paper can be easily picked up with some knowledge of basic arithmetic and some modular algebra. There are two basic types of encryption: substitution and transposition. We will cover the basics of each with some easy examples. Since this is an introduction, the techniques will be easier. After reading a section, try to improve on the method by coming up with your own versions. 1.1 Alice, Bob, and Eve Suppose Alice wants to send Bob a message. She doesn't want Eve to intercept it and read it, so she decides to disguise it. Here's a diagram that outlines the what's happening. Your hope is that Eve doesn't know how to figure out your message or alter it in some way. 1 INTRODUCTION 4 1.2 Basic Terminology 1. Plaintext - this is the original message to be sent. It can letters, numbers, characters, symbols, etc. 2. Encryption - disgusing the plaintext using some method. These methods usually have a key or algorithm to generate the ciphertext. 3. Ciphertext - the result of the encryption. It can be letters, numbers, characters, etc., but unreadable. 4. Decryption - the process of undoing the encryption. You should get the original plaintext when finished. 5. Key - something that is used to encrypt the message. Think of it as a password that disguises and un-disguises your message. 6. Keyspace - the set of all possible keys. For example, a four digit lock has 10000 possible keys. (0000, 0001, 0002, ..., 9998, 9999) 7. Cryptography - the science of the enciphering and deciphering of messages in secret code or cipher. Also referred to as cryptology. 8. Cryptosystem - a system for encrypting information. 9. Cryptanalysis - the science (and art) of recovering information from ciphers without knowledge of the key. 1.3 Brief History of Cryptography Cryptography is an ancient science. The term comes from the Greek language meaning "the study of hidden or secret writing." Ever since there were multiple tribes (or countries), we needed a way to communicate to one another without the other tribe (country) understanding it. Today it's vital to communicatations, authentication, sending sensative data over the internet, purchasing items from 1 INTRODUCTION 5 eBay, Amazon, and more. One of the earliest examples of cryptography was in Egypt around 2000 B.C. where they used hieroglyphics to decorate their tombs. Even though they weren't trying to completely hide the meaning, it still wasn't easy to interpret. The Greek writer Polybius used a 5x5 or a 6x6 (with out alphabet) to disguise the message. Below is an example of how it would work, If you wanted to write the message "SAVE ME", it would be disguised as S-A-V-E-M-E 41-11-44-15-31-15 Another Greek tool for disguising a message was called the Scytale. It is a tool used to perform a transposition cipher, consisting of a cylinder with a strip of parchment wound around it on which is written a message. In other words, it was a way to rearrange the letters. You would wrap a long thin parchment around a rod. You then write your message across the rod, "SEND HELP!" 1 INTRODUCTION 6 When you unwrap the parchment the letters appear rearranged. To understand the message, the receiver would need a rod of the same size. Julius Caesar used his own way of disguising messages to send to his military. We know call it the Caesar Cipher. If he had anything important to send, he would write out his message and then replace each letter of his message with another letter down the alphabet. So A = D, B = E, C = F, D = G, etc. When it needed to be read, the receiver of the message would reverse this process, changing D back to A, E back to B, F back to C. We will go over this method in great detail in the next chapter. The tool we will use will look something like this, 1 INTRODUCTION 7 This method is a form of substitution, where you replace one letter for another. Over the years, the substitution method evolved. In this next chapter, we discuss the Keyword Cipher, which is another form of substitution. The Vigenere cipher was a substitution cipher where each letter of the message used its own caesar shift. This means the first letter might be shifted by 3 letters, the second letter of the message could be shifted by 5 letters, the third letter by 3, the fourth letter by 5, the fifth letter by 3, and so on. This particular pattern would be two Caesar shifts with 3 and 5. For 300 years it was believed to be indecipherable. It can now be broken by determining the number of different caesar shifts and then do a frequency analysis on the letters that use the same Caesar shift. To give you an idea, suppose your keyword is "DOG" and you want to disguise the message "HELP ME", you use the Vigenere Table below to determine the ciphertext. 1 INTRODUCTION 8 Message: H E L P M E Keyword: D O G D O G Cipher: K S R S A K Why was this cipher so strong? Consider the ciphertext. There are two 'K's but each corresonds to a different letter in the plaintext. One 'K' decrypts back to H while the other 'K' decrypts to E. In 1917 U.S. Army Major Joseph Mauborgne developed a technique known as the One-Time Pad. It works the same way as a Vigenere Cipher. The only 1 INTRODUCTION 9 difference is the keyword is a random string of letters that is the same length as the message. That way the keyword never repeats which makes frequency analysis useless. If this method is done correctly, it is the only provably unbreakable encryption algorithm. Here's an example. Suppose the ciphertext is "KNEXYLTCOW." Now suppose you used two different one-time pad keys, "AFTMRDARKF" and "DJWMRDARKF". Let's see what happens. Use the Vigenere Table to convert back to plaintext. Cipher: K N E X Y L T C O W Key: D J W M R D A R K F Plaintext: H E I L H I T L E R Cipher: K N E X Y L T C O W Key: A F T M R D A R K F Plaintext: K I L L H I T L E R This means you can make the plaintext say anything you want. But there are two main weaknessess to this method. 1. Making sure the key is random and of sufficient length. 2. Distributing the keys. How is the receiver suppose to know which key to use? One way to accompish the distribution of keys is to have an agreed upon book. Each day the random key starts with the first letter of a page in that book. Keep reading the letters from the page until it's the same length as the message. Another interesting use of crytography was to send messages through newspapers. Before the telegraph, people needed to send messages through the mail. Postage could be expensive, plus someone could intercept the letter. Newspapers traveled freely and without charge. So someone could publish an article in the newspaper and put a dot above the letter that was part of the plaintext. For example, 1 INTRODUCTION 10 I_am excit_ed t_oa _nnounce the wedding of my brother. He is ba_ck_ from his journey overseas and is looking forward to a new life with his beautiful bride. Excluding i's, which would have two dots, the letters with dots above them spell attack World War II The Germans adopted the use of a family of electro-mechanical encryption devices invented by the German engineer Arthur Scherbuis.