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: Ken LambertCiphertext: I?
Example Encryption
Plaintext: Ken LambertCiphertext: I?%Y
Example Encryption
Plaintext: Ken LambertCiphertext: I?%Y!4
Example Encryption
Plaintext: Ken LambertCiphertext: I?%Y!4bm
Example Encryption
Plaintext: Ken LambertCiphertext: I?%Y!4bmPb
Example Encryption
Plaintext: Ken LambertCiphertext: I?%Y!4bmPbt
Last step does not use the matrix, because the plaintext contains an odd number of characters
Decryption
Plaintext: Ken LambertCiphertext: I?%Y!4bmPbt
The same matrix and algorithm are used to decrypt or generate the plaintext from the ciphertext
The Algorithm
Set the ciphertext string to the empty stringFor 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 stringIf the number of characters in the plaintext string is odd Append its last character to the ciphertext stringReturn 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
0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT 1 LF VT FF CR SO SI DLE DC1 DC2 DC3 2 DC4 NAK SYN ETB CAN EM SUB ESC FS GS 3 RS US SP ! " # $ % & ` 4 ( ) * + , - . / 0 1 5 2 3 4 5 6 7 8 9 : ; 6 < = > ? @ A B C D E 7 F G H I J K L M N O 8 P Q R S T U V W X Y 9 Z [ \ ] ^ _ ' a b c 10 d e f g h i j k l m 11 n o p q r s t u v w 12 x y z { | } ~ DEL
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.
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