Top Banner
Lecture 14 Module 5 Presentation Layer and Application Layer Prepared by Sam Kollannore U. Assistant Professor Department of Electronics M. E. S. College Marampally Email: [email protected], [email protected]
48
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 14

Lecture 14Module 5

Presentation Layerand

Application LayerPrepared by

Sam Kollannore U.Assistant Professor

Department of ElectronicsM. E. S. College Marampally

Email: [email protected], [email protected]

Page 2: Lecture 14

Presentation Layer functions

• Translation• Encryption/Decryption• Authentication• Compression

Page 3: Lecture 14

1. Translation• Internal representation of a piece of information might vary from

one machine to another• Eg. Different forms to represent a character string – ASCII code/

EBCDIC code• Presentation layer solves the problem by translation• Direct or indirect translation

– Not acceptable – need several conversion tables

• Direct: ASCII code is translated to EBCDIC code at the receiver• Indirect: ASCII code is translated to a standard format at the sender

and translated into EBCDIC at the receiver– Recommended by OSI– Called ASN.1 (Abstract Syntax Notation 1)

Page 4: Lecture 14

ASN.1

Handles- Diverse nature of data : text, program etc- Diversity in data storage

Provides mechanism for defining data types - integer, real, bits, strings etc

Uses the concept of objects

Page 5: Lecture 14

2. Encryption / Decryption• Sender transforms the original information to another form

(Encryption) and sends the resulting unintelligible message out over the network

• Decryption – reverses the encryption process in order to transform the message back to its original form

• Message to be encrypted – plaintext• Transformed by a function called Key• Encrypted message – Ciphertext (Cryptogram)• Receiver uses a decryption algorithm and a key to transform

the Ciphertext back to the original plaintext• Enemy or intruder hears and copies down the complete

ciphertext • Two types of intruders : Passive – just listens

Active – alter messages

Page 6: Lecture 14

Encryption model

The art of breaking ciphers is called cryptanalysis, and the art devising them (cryptography) is collectively known as cryptology.

KdKe

Page 7: Lecture 14

Encryption /Decryption methods

• Conventional methods – Encryption key (Ke) and the decryption key (Kd) are the same and secret– Character level encryption– Bit level encryption

• Public key methods

Page 8: Lecture 14

Character level encryption

i) Substitutional ii) Transpositional

Substituitonal - simplest form of character level encryption a) Monoalphabetic substitution – Caesar Cipher- Encryption : Each character is replaced by another character in the set – by simply adding a number to the ASCII code of the character- Decryption : subtracts the same number i.e. Ke and Kd are the same DEAR GHDU- Code can be broken easily

Page 9: Lecture 14

b) Polyalphabetic substitution – each occurrence of a character can have a different substituteEg. Ke / Kd = Position of the character in the text DEAR DEAR FRIEND EGDV JLIA QDVSCT- code can be easily broken by an experienced snooper

Another example : Vignere cipher- key is a two-dimensional table (26 X 26)- First row ABCD…XYZ- second row BCDE…YZA- last row ZABC…WXY• To replace a character, the algorithm finds the position of the character in the text is

used as the row number; position of the character in the alphabet is used as the column number

• Algorithm substitutes the character with the character in the table that corresponds to the column and row number

Page 10: Lecture 14

Transpositional- characters retain their plain text form but change their positions to create the ciphertext- text is organized into atwo dimensional table and the columns are interchanged according to a key

Ke = Kd

1 2 3 4 5 6 7 8 9 10 11

A G O O D G O O D

F R I E N D I S

B E T T E R T H A N

A T R E A S U R E

1 2 3 4 5 6 7 8 9 10 11

D G G O A O O O D

D I I N F S R E

R T T E B A H E T N

A S T U E A E R R

1 2 3 4 5 6 7 8 9 10 11

6 9 3 10 5 1 2 4 8 7 11

Page 11: Lecture 14
Page 12: Lecture 14

Bit level EncryptionData as text, graphics, audio or video are first divided into blocks

of bits , then altered by encoding/decoding, permutation, substitution, exclusive OR, rotation and so on..

• Encoding/decoding– Decoder changes an input of n bits into an output of 2n bits– Output should have only one single 1, located at the position

determined by the input– Encoder do the opposite function

2 X 4 Decoder

Input Output

0 0 0 0 0 1

0 1 0 0 1 0

1 0 0 1 0 0

1 1 1 0 0 0

Page 13: Lecture 14

Permutation – transposition at the bit level1. Straight permutation: no. of bits in the i/p and o/p are preserved2. Compressed permutation – number of bits is reduced 3. Expanded permutation – number of bits is increased

A permutation unit can be made as a hardware circuits / units called P-boxes

Substitution – Substitution of n bits by another n bits : S-box- Combination of P-boxes, encoders and decodersProduct – Several stages of P-boxes and S-boxes are combinedExclusive ORThe input and the key are exclusive ORed to create the outputThe same key can be used with the ciphertext at the receiver to recreate

the original patternRotation – rotate bits to the right or leftKey : number of bits to be rotated

Page 14: Lecture 14
Page 15: Lecture 14

Example of bit-level encryption – Data Encryption standard (DES)

• Designed by IBM • Adopted by the US govt. for nonmilitary and nonclassified use• Algorithm encrypts a 64-bit plaintext using a 56-bit key • Text is passed through 19 different complex procedures• First and the last step are simple (transposition)• Steps 2 to 17 are complex; each requiring substeps that are

combinations of transposition, substitution, swapping, EXOR and rotation

• Although steps 2 to 17 are the same , each uses a different key derived from the original key

• Each step uses the output of the previous step as its input

Page 16: Lecture 14

Public Key methods• In conventional methods anyone who knows the encryption

algorithm and key can deduce the decryption algorithm• Public key encryption is used to increase the level of secrecy• Used when there are many senders and one receiver• Example: Bank wants to give the customers remote access to

their accounts – every user has the same encryption algorithm and key; but the decryption algorithm and the key are kept secret (not the inverse of encryption algorithm)

• i.e anyone can encrypt the information but only the authorized receiver (bank)can decrypt it

Page 17: Lecture 14

RSA EncryptionRivest, Shamir, Adleman encryption

• One party (a bank customer for example) uses a public key, Kp• The other party uses a secret (private) key, Ks• Both use a number, N

Encryption algorithm steps:- Encode the data to be encrypted as a number to create the

plaintext, P- Calculate the ciphertext C as C = PKp modulo N- Send C as ciphertext

Decryption algorithm steps:- Receive C, the ciphertext- Calculate plaintext P = CKs modulo N- Decode P to the original data

Page 18: Lecture 14

Customer

Kp and N

C = PKp modulo N P = CKs modulo N

Bank

Ks and N

Encryption Decryption

Plaintext Ciphertext Plaintext

PP C

For example : Kp = 5, Ks = 77 and N = 119Character F is encoded as 6. We calculate 6Kp modulo 119 = 41. At the receiver, we calculate 41Ks modulo 119 = 6 and then decode 6 as F

Choosing Kp, Ks and N• Choose two prime numbers p and q ( say 7 and 17)• Calculate N = p x q (N = 7 x 17 = 119)• Select Kp such that it is not a factor of (p – 1) x (q – 1) = 96. The factors of

96 are 2, 2, 2, 2, 2 and 3. We choose 5, which is not a factor of 96• Select Ks such that (Kp x Ks) modulo (p – 1) x (q -1) = 1. We choose 77.

If you check, you will see that in our example, 5 x 77 = 385 and 385 = 4 x 96 +1

Mathematicians have calculated that, for example, it would take more than 70 years to find the prime factors (p and q) of a number with 100 digits

Page 19: Lecture 14

• An example of the RSA algorithm.

Diffie-Hellman algorithm – refer Forouzan 4th edition P.No. 952

Page 20: Lecture 14

3. Authentication• Verifying the identity of a sender – to verify that a message is

coming from an authentic sender• Digital signature – based on public key encryption/decryption• Uses the reciprocity of RSA (Kp and Ks are reciprocals)• Customer uses one public key and one secret key and the

bank uses one secret key and one public key

Customer Ks-1 Bank

Encryption/Decryption

Authentication

PP C2Kp -1

C1Ks-2 Kp -2

C1

Saved in a file

Page 21: Lecture 14

Data Compression• Lossless compression

- Run length encoding- Statistical compression- Morse code- Huffman encoding- LZW (Lempel-Ziv-Welch) encoding

- Relative compression

• Lossy compression- Predictive encoding - to compress audio - Perceptual encoding : MP3 – to compress audio- JPEG – to compress images- MPEG – to compress video

Page 22: Lecture 14

Lossless compressionRun length encoding

• Repeated strings are replaced by a special marker, followed by the repeated symbol and the number of occurrences

• Used in audio (silence is a run of 0s) and video (run of picture elements having the same brightness and colour

Original data : 572644444444432133333333333333333331278000000000000000Compressed data : 5726#409321#3191278#015

Statistical CompressionUses short code for frequent symbols and long codes for infrequent symbolsLength of the total data is reduced tremendouslyThree types:1.Morse code2.Huffman encoding3.LZW encoding

Page 23: Lecture 14

Morse Code• Uses variable length combination of mark (dash) and space

(dot) to encode data• One-symbol code most frequent characters• Five-symbol code least frequent characters

• Examples ∙ E

− ∙ A

− ∙ N

− − − − ∙ Q

Page 24: Lecture 14

Huffman encoding• Uses variable length codes (a string of 0s and 1s) to encode a set of symbols• Example: encode the data MALAYALAM

LZW encoding• Adaptive coding• Dictionary based compression technique• Used fixed length code words to represent variable length strings of symbols /characters• LZW encoder and decoder develop the same dictionary• Since a single code can represent more than one symbol/character, data compression is realized• For eg. Instead of transmitting 14 characters, if LZW transmits only 9 codes, then the

compression ratio = 14/9 = 1.56(Looks for repeated strings or words and stores them in variables – then replaces occurrences of that string with a pointer to that variable)

Page 25: Lecture 14

LZW coding example

A B A B B A B C A B B A B B A X 1 2 4 5 2 3 6 6 1

Dictionary

index entry

1 A

2 B

3 C

4 AB

5 BA

6 ABB

7 BAB

8 BC

9 CA

10 ABBA

11 ABBAX

Page 26: Lecture 14

Relative Compression or differential encoding

• Used for video compression• Commercial TVs send 30 frames of 0s and 1s every second• Only little difference between consecutive frames• We send only the difference between consecutive frames• Small differences can be encoded into small streams of bits

Page 27: Lecture 14

Lossy CompressionDigitizing audioVoice – 8000 samples per second with 8 bits per sample –

resulting in a digital signal of 64kbpsMusic – 44100 samples per second with 16 bits per sample –

resulting in a digital signal of 705.6kbps for monaural and 1.411 Mbps for stereo

Digitizing videoNumber of frames per second = 2 X 25Each pixel is 24 bits (8 bits for each primary colour)Lowest resolution colour frame – 1024 X 768 i.e. we need 2 X 25 X 1024 X 768 X 24 = 944 Mbps

To send video using lower-rate technology , we need to compress the video

Page 28: Lecture 14

Audio compressionTwo techniques for audio compression 1. Predictive encoding

- difference between the samples are encoded instead of encoding all the sampled values- Normally used for speech- GSM (13 kbps), G.729 (8 kbps) and G.723.3(6.4 or 5.3 kbps)

2. Perceptual encoding : MP3- based on the science of psychoacouctics (study of how people perceive sound)- some sounds can mask other sounds - masking can happen in frequency and time Frequency masking – a loud sound in a frequency range can partially or totally mask a softer sound in another frequency rangeTemporal masking – a loud sound can numb our ears for a short time even after the sound has stopped

Page 29: Lecture 14

• MP3 uses frequency and temporal masking to compress audio signals

• Analyzes and divides the spectrum into several groups– Zero bits are allocated to the frequency ranges that are totally masked– Few bits are allocated to the frequency ranges that are partially masked– Large number of bits are allocated to the frequency ranges that are not

masked

• MP3 produces three data rates: 96 kbps, 128 kbps and 160 kbps

Page 30: Lecture 14

Image CompressionJPEG – Joint Photographic Experts Group- Exploits spatial redundancy• A gray scale picture is divided into blocks of 8 X 8 pixels (macro block)

– to decrease the number of calculations• JPEG – change the picture into a linear (vector) set of numbers that

reveals the redundancies• The redundancies (lack of changes) can then be removed by using one

of the text compression methods

Page 31: Lecture 14

DCT – Discrete Cosine Transform- changes the 64 values so that the relative relationships between pixels are kept but the redundancies are revealed

Transformation creates table T from table P T(0,0) DC value - is the average (multiplied by a constant)

of the P(x,y) Rest of the values, called ac values are the changes Lack of changes in the neighbouring pixels creates 0s

Page 32: Lecture 14

Quantization• To reduce the number of bits needed for encoding• We divide the number by a constant and then drop the fraction• Divisor depends on the position of the value in the table• Losses some information (hence the name lossy compression )

Another example

Page 33: Lecture 14

Compression• After quantization, the values are read from the table• Redundant 0s are removed • Table is read diagonally in a zig-zag fashion (the reason is that

if the picture changes smoothly, the bottom right corner of the T table is all 0s)

Page 34: Lecture 14

Video Compression : MPEG• Motion picture is a rapid flow of a set of frames, where each frame is an

image

• Frame spatial combination of pixels• Video temporal combination of frames• Compressing video spatially compressing each frame and temporally

compressing a set of frames• Spatial compression – done by JPEG or its modification • Temporal compression – redundant frames are removed • For temporal compression, MPEG divides frames into three categories:

• I-frames : Intracoded frame• P-frame : Predicted frame• B-frame : Bidirectional frame

Page 35: Lecture 14

• I-frames– Independent frame not related to any other frame and cannot be constructed

from other frames– Present at regular intervals (eg. Every ninth is an I-frame)– When a video is broadcast, a viewer may tune-in at any time. If there is only

one I-frame at the beginning, the viewer who tune-in late will not receive a complete picture

• P-frames– Related to the preceeding I-frame or P-frame – i.e. each P-frame contains only the changes from the preceeding frame– Carry much less information than other frame types

• B-frames– Related to the preceeding and following I-frame or P-frame (relative to the past

and the future)– a B-frame is not related to another B-frame

Page 36: Lecture 14
Page 37: Lecture 14

MPEG frame construction

MPEG 1 designed for a CD ROM – data rate of 1.5 MbpsMPEG 2 designed foe high quality DVD – data rate of 3 to 6 MbpsMPEG 4 designed to handle multimedia presentations and applications over

internet and mobile/wireless network – data rate upto 10 MbpsMPEG 7 audiovisual content-based (or object) retrieval in digital libraries

Page 38: Lecture 14

Application Layer

• Holds the user program that do the actual work for which the computers were purchased by making use of the service offered by the presentation layer

Functions of Application layer• FTAM – File Transfer, Access and Management• Electronic Mail• Virtual Terminals

Page 39: Lecture 14

1. FTAM• File transfer – by sharing the common files

– Copy of the original files stored in one machine are transferred to other machine when needed

– Each file ‘live’ on the machine where it was created and the users on the other machines can ask for copies when needed

• Remote File Access- Similar to file transfer but only pieces of files are read or written rather

than entire files– Files are located on File server machines and users on Client machine – Most modern file servers – Virtual File store – presents a standardized

interface to its clients – transfers based on standardized protocols

Page 40: Lecture 14

1.1 File Servers• File structure

– Unstructured file – only read/write on part of files– Flat file – ordered sequence of records – not of same size/type –

operations on individual records

– Hierarchical file – shape of a treeeach node may have a label, data record, bothor neither

• File Attributes – name, size, owner, access control, date and time of creation etc

• File operations – can apply to a file as a whole or to its contents in individual records- Create, delete etc

Page 41: Lecture 14

1.2 Concurrency control

• If two or more files are accessed at the same time, problems can occur – solved by using locks

• Shared lock – client request a shared lock on a file at the time a file is opened

• To prevent the file from being changed by other readers while reading - granted only if the file is unlocked

• Exclusive locks– Used for writing– To make sure that no other readers or writers are active while

writing– Granted only on unlocked files

Page 42: Lecture 14

1.3 Replicated files

• When dealing with multiple servers and multiple clients, files are replicated.

• Problems while making updation – handled by1. Primary copy replication – one copy is master and all others are slaves– Updates are made to the master and propagated to slaves

2. Voting – a read can be done by obtaining a read quorum Nr and a write can be done by acquiring a write quorum Nw; such that Nr + Nw > N where N- number of servers having copies of a file

Page 43: Lecture 14

2. E-mail• CCITT define a series of protocols - in its X.400 recommendations –Message

Handling Systems (MHS)• OSI incorporated these in application layer under the name MOTIS (Message

Oriented Text Interchange Systems)• Architecture and Services of MOTIS and X.400

- composition- Transfer- Reporting- conversion- Formatting- Disposition- mail boxes- distribution list

Three basic types of messages• User message• Replies• Probes

Page 44: Lecture 14

User Agent

Message Transfer Agent

MS

Presentation Layer

User Agent

Message Transfer Agent

MSMessage Transfer

Agent

Originator’s terminal

Recipient's terminal

P2

P3

P1P1

P7P7 P3

Message Transfer System

Page 45: Lecture 14

3. Virtual Terminals

Local Host

Terminal (Monitor & Keyboard)

Local HostTerminal (Monitor & Keyboard)

Network

Remote Host

Page 46: Lecture 14

Operating system

VT software

Operating system

VT software

Networkstructure structure

Terminal (Monitor & Keyboard)

Terminals falls in three broad classes1.Scroll mode – no built-in microprocessors – communicate with the network using a PAD (Packet Assembler/Dissambler or’black box’)2.Page mode – CRT terminals that can display 25 lines of 80 characters each3.Form mode – have built-in microprocessors – used in applicaions like banking, airline reservations etc

Page 47: Lecture 14

4. Job Transfer and Management (JTM)• Individual prepares some work on his personal computer that must

be run on a mainframe using files located on his department’s mini computer with the results to be sent back to the personal computer

• Applications that manages this kind of remote job entry is called JTM• JTM knows nothing about the contents of files, job control languages

or the nature of processing• Problems to be solved

– Every system involved must have a unique name – Authentication : whethet user has permission to access the JTM

requested file or who to charge for the CPU time– JTM is responsible for monitoring progress and reporting it

Page 48: Lecture 14

5. Teletext6. Videotex• Refer P.Nos. 574-576 : Andrew S. Tanenbaum,

Second Edition