Computer Science 101 Data Encryption And Computer Networks Reading for This Week and Next Week • Chapter 7 - Networks, the Internet and the Web • Chapter 8 - Information Security The Problem • Back in the old days, information was kept secure by locking the door to the computer room • When computers are connected via networks and information can be transmitted, we need another way to secure it • What happens when you send your credit card number to Amazon? Cryptography • The science of secret writing – thousands of years old • Encrypt plain text into a cipher text, using a cipher key • Decrypt cipher text back into plain text, using a cipher key A Simple Algorithm: The Caesar Cipher • Let S = an integer between 1 and 25 • Encode each letter in plain text by replacing it with the letter that is S positions to its right in the alphabet • Shift the last S letters in a cycle to the first S letters Example Encryption • Let S = 3 • Then A encodes as D, B as E, X as A, etc. • ARMY encodes as DUPB Problem With Caesar Cipher • Because there are only 25 possible keys, one can decode a cipher text by brute force, by trying all possible keys (a computer makes that easy) • Caesar cipher is a stream/substitution cipher, wherein each letter of plain text generates a letter of cipher text • The structure of the plain text is preserved in the structure of the cipher text Block Cipher • Encode a block of plaintext letters as a block of cipher text letters • More difficult for a cryptanalyst (i.e., a hacker) to detect the patterns The Key: An Encryption Matrix A two-dimensional grid of characters Each successive pair of characters in the plaintext maps to a pair of characters in the ciphertext Example Encryption Plaintext: Ciphertext: Ken Lambert I? Example Encryption Plaintext: Ciphertext: Ken Lambert I?%Y Example Encryption Plaintext: Ciphertext: Ken Lambert I?%Y!4 Example Encryption Plaintext: Ciphertext: Ken Lambert I?%Y!4bm Example Encryption Plaintext: Ciphertext: Ken Lambert I?%Y!4bmPb Example Encryption Last step does not use the matrix, because the plaintext contains an odd number of characters Plaintext: Ciphertext: Ken Lambert I?%Y!4bmPbt Decryption The same matrix and algorithm are used to decrypt or generate the plaintext from the ciphertext Plaintext: Ciphertext: Ken Lambert I?%Y!4bmPbt The Algorithm Set the ciphertext string to the empty string For each pair of characters in the plaintext string Locate the positions of each character in the matrix If the positions are in the same row or column, then Append the two characters in reverse order to the ciphertext string else Locate the opposite corners of the imaginary rectangle formed by these positions Append the two characters at these corners to the ciphertext string If the number of characters in the plaintext string is odd Append its last character to the ciphertext string Return the ciphertext string Other Cryptography Issues • The key must be sent with the message • So, the key must be encrypted • Send a public key to encrypt • Keep a different, private key to decrypt Network Transmissions • Sender and receiver have different responsibilities • Sender must encode information provided by user • Receiver must notify sender to resend if some info is lost or corrupted • Receiver must decode info for user Encoding for Network Transmission • Translate text to binary form • Encrypt binary form if necessary • Place each code in a packet • Add a parity bit and a label to the packet The ASCII Character Set • American Standard Code for Information Interchange • A set of 128 numbers, ranging from 0 to 127 • Each character maps to a number The ASCII Character Set 0 1 2 3 4 5 6 7 8 9 10 11 12 0 NUL LF DC4 RS ( 2 < F P Z d n x 1 SOH VT NAK US ) 3 = G Q [ e o y 2 STX FF SYN SP * 4 > H R \ f p z 3 ETX CR ETB ! + 5 ? I S ] g q { 4 EOT SO CAN " , 6 @ J T ^ h r | 5 ENQ SI EM # 7 A K U _ i s } 6 ACK DLE SUB $ . 8 B L V ' j t ~ 7 BEL DC1 ESC % / 9 C M W a k u DEL 8 BS DC2 FS & 0 : D N X b l v ASCII 32 to 126 are codes for the printing characters ASCII 0 to 31 and 127 are codes for control characters Row # + column # locates character and specifies code Thus, the ASCII code for ‘A’ is 65, etc. 9 HT DC3 GS ` 1 ; E O Y c m w Step 1: Translate Character to Binary ‘A’ translates to ASCII 65 ASCII 65 translates to 01000001 binary We use 8 bits for each character Step 2: Encrypt Subtract an offset and shift bits a certain distance to the left or right We’ll subtract 1 and shift the bits to the right by 1 Subtract 1: 01000001 01000000 Shift right by 1: 01000000 00100000 The encoded ‘A’ is ASCII 32, or ‘ ’ (the space) Step 3: Place Code in a Packet Each packet contains • two character codes • a parity bit • a label that identifies the position of the packet in the original message • If there is no character available, we use ASCII for the null character (0) to hold the place in the packet Step 3: Place Code in a Packet Null (00000000) encrypts as 11111111 00100000 + 11111111 = 0010000011111111 (odd # of 1s) Add parity bit: 0010000011111111 0 Add label (first of four packets): 00 0010000011111111 0 Receiving and Decoding • Wait for all labeled packets to be placed in correct order • Check parity bit for corrupted data • Decrypt to binary • Decode to ASCII and then to text