CRYPTOGRAPHY Digital Diva March 2012 Eastern Michigan University Professor S. Haynes, shaynes@emich.edu URL for this material: http://people.emich.edu/shaynes/DigitalDiva2012 Shift Substitution Permutation Tap Code Steganography Book Cipher Playfair No hay tarea :-( Definitions Plaintext: Ciphertext: an unencrypted message an encrypted message Cipher: encrypt, ciphertext, encryption algorithm Encryption: transforming plaintext into ciphertext so that the plaintext is kept a secret; this usually requires use of a key. Decryption: transforming ciphertext into plaintext; this usually requires use of a key. Encode: transform something into something else. For example, English Spanish, letters to numbers (a, b, c, … z) (1, 2, 3, … 26). Decode: undo an encoding (Spanish English; (1, 2, 3, … 26) (a, b, c, … z) ). Algorithm: A sequence of instructions to accomplish something. Key: Something that is known to the sender and the receiver of a message and is used to encrypt and decrypt messages. Secret key (aka private key, symmetric key, shared key): the sender and the receiver have exactly the same key. The sender encrypts with the secret key, the receiver decrypts with the same secret key. Public key (aka asymmetric key): a key that comes in two parts: (1) public and (2) private. Shift cipher: To encrypt plaintext, shift each plaintext letter to the right by key steps. To decrypt ciphertext, shift each ciphertext letter to the left by key steps. Substitution cipher: Each plaintext letter is converted to a specific cipher text letter; each cipher text letter is decrypted to the original plaintext letter. Steganography: the secret message is hidden in another message. Alice: the sender of a message Bob: the receiver of a message Shift cipher 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 a b c d e f g h i j k l m n o p q r s t u v w x y z The shared key, k, is the size of the shift Encryption algorithm: Each plaintext letter is encrypted as the letter k positions to the right with wrap-around. Decryption algorithm: Each ciphertext letter is encrypted as the letter k positions to the left with wrap-around. Example Encryption, key = 3 (Caesar cipher) Plaintext: lazy one Ciphertext: odcb rqh Example Decryption Ciphertext: tzlc Plaintext: quiz Substitution cipher Each plaintext letter is matched to a unique ciphertext letter. Example Plaintext: a b c d e f g h i j k l m n o p q r s t u v w x y z Ciphertext: Z A B Y C D X E F W G H V I J U K L T M N S O P R Q The key for a substitution cipher is a permuted alphabet. Simple ways to form a key: - a shift cipher is a substitution cipher - reverse the alphabet - pick a word or phrase, e.g., “go green beat toledo”. Write down each letter in order from the phrase under the alphabet, without repetition. Then complete the alphabet by copying the unused letters in order. You’ll see the same idea in Playfair cipher later. Example: a b c d e f g h i j k l m n o p q r s t u v w x y z G O R E N B A T L D C F H I J K M P Q S U V W X Y Z Permutation The key is the permutation order. Break the plain text message into blocks of size k. Number the letters in each block in order 0, 1, 2, … k-1. Encrypt each block separately following the permutation order given by the key. To decrypt, find the permutation that will undo the encryption permutation. Then follow the same steps as encryption with the new (inverse) permutation. Example Block size = 8 key = 0 7 1 2 6 5 3 4 to undo permutation: 0 2 3 6 7 5 4 1 Labelled blocks: 0 1 2 3 4 5 6 7 n o w i s t h e 0 1 2 3 4 5 6 7 t i m e f o r a 0 1 2 3 4 5 6 7 l l g o o d m e 0 1 2 3… n x q x… Permute according to the key. This is the ciphertext. N E O W H T I S T A I M R O E F L E L G M D O O N X X… To decrypt: 0 1 2 3 4 5 6 7 N E O W H T I S 0 1 2 3 4 5 6 7 T A I M R O E F 0 1 2 3 4 5 6 7 L E L G M D O O 0 1 2 N X X… n o w i s t h e t i m e f o r a l l g o o d m e n x q … Tap Code The plain text is given inside the grid, the cipher text is the corresponding row and column numbers. So for the letter ‘i’, you would tap two times for the row, then four times for the column: .. 1 2 3 4 5 1 A F L Q V 2 B G M R W 3 C H N S X 4 D I O T Y .... 5 E J P U Z The space between letters is a little longer than the space between row and column. End of sentence is marked with ‘x’ (..... ... ) Use the letter ‘C’ if you need a ‘K’. Steganography Hidden writing has many possibilities: Invisible ink “Subliminal advertising” “Meaningful” stitches in quilts (e.g., 3 french knots to indicate a ‘c’, 4 to indicate a ‘d’) Pin pricks in letters For our example, we’re using differences in style to mark significant letters or words. “Book cipher” To my memory, Sherlock Holmes broke two ciphers. One was a simple substitution cipher. The other was a book cipher. To use a book cipher, sender and receiver must agree on exactly the same edition and printing of a particular book. The key is how the address of a word is specified, for example: page#, line#, word# Each word of the plaintext is encrypted by finding the word in the common text, then producing that word’s address as the ciphertext. Playfair cipher This cipher uses a 5 X 5 grid, where the letters of the alphabet are laid out (I and J occupy the same cell). The key is a word or phrase. To fill in the grid, copy the key, without any duplication of the letters (left to right, top to bottom), then fill in the rest of the grid with any unused letters in order. Example grid: key = “crypto rocks” C O D I/J U R K E L V Y S F M W P A G N X T B H Q Z To encrypt: Divide the plain text into two letter blocks with the following “fix”: no block can have two identical letters. To avoid that, insert an ‘x’ after the first letter. Example: calling gramma ca lx li ng gr am ma ^ Find the two letters of a single block on the grid. There are three possibilities: (1) The two letters form two of the four corners of a rectangle (e.g., ‘ca’) output the other two corners, row first ca PO pk RA (2) The two letters are on the same row (e.g., ‘ks’) Output the two letters found by moving one space right of each letter: ks SA If you run out of room on the right, then do wrap-around: eh -> FD (3) The two letters are on the same column (e.g., ‘ag’) Output the two letters found by moving one space down from each letter: ag GN, Rl KV. If you run out of room on the bottom, then do wrap-around: rv KR, gx NP Decryption: Case (1), same as for encryption. Case (2), move left Case (3), move up