You are on page 1of 48

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: sam.koll@yahoo.com, samkoll.mes@gmail.com
Presentation Layer functions
• Translation
• Encryption/Decryption
• Authentication
• Compression
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)
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
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
Encryption model

Ke Kd

The art of breaking ciphers is called cryptanalysis, and the art


devising them (cryptography) is collectively known as cryptology.
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
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
b) Polyalphabetic substitution – each occurrence of a character can have a different
substitute
Eg. 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
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
6 9 3 10 5 1 2 4 8 7 11

1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 11
A G O O D G O O D D G G O A O O O D
F R I E N D I S D I I N F S R E
B E T T E R T H A N R T T E B A H E T N
A T R E A S U R E A S T U E A E R R
Bit level Encryption
Data 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
Permutation – transposition at the bit level
1. Straight permutation: no. of bits in the i/p and o/p are preserved
2. 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 decoders
Product – Several stages of P-boxes and S-boxes are combined
Exclusive OR
The input and the key are exclusive ORed to create the output
The same key can be used with the ciphertext at the receiver to recreate
the original pattern
Rotation – rotate bits to the right or left
Key : number of bits to be rotated
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
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
RSA Encryption
Rivest, 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
Kp and N Ks and N
P C P
Customer C = PKp modulo N P = CKs modulo N Bank
Plaintext Ciphertext Plaintext
Encryption Decryption
For example : Kp = 5, Ks = 77 and N = 119
Character 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
• An example of the RSA algorithm.

Diffie-Hellman algorithm – refer Forouzan 4th edition


P.No. 952
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

Saved in a file

P C1 C2 C1 P
Customer Ks-1 Kp -1 Ks-2 Kp -2 Bank

Encryption/Decryption

Authentication
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
Lossless compression
Run 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 : 572644444444432133333333333333333331278000000000000000
Compressed data : 5726#409321#3191278#015

Statistical Compression
Uses short code for frequent symbols and long codes for infrequent
symbols
Length of the total data is reduced tremendously
Three types:
1.Morse code
2.Huffman encoding
3.LZW encoding
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
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)
LZW coding example

ABABBABCABBABBAX Dictionary
index entry
12 4 5 2 3 6 6 1
1 A
2 B
3 C
4 AB
5 BA
6 ABB
7 BAB
8 BC
9 CA
10 ABBA
11 ABBAX
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
Lossy Compression
Digitizing audio
Voice – 8000 samples per second with 8 bits per sample –
resulting in a digital signal of 64kbps
Music – 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 video
Number of frames per second = 2 X 25
Each 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
Audio compression
Two 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 range
Temporal masking – a loud sound can numb our ears for a short time even after
the sound has stopped
• 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
Image Compression
JPEG – 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
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
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
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)
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
• 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
MPEG frame construction

MPEG 1  designed for a CD ROM – data rate of 1.5 Mbps


MPEG 2  designed foe high quality DVD – data rate of 3 to 6 Mbps
MPEG 4  designed to handle multimedia presentations and applications over
internet and mobile/wireless network – data rate upto 10 Mbps
MPEG 7  audiovisual content-based (or object) retrieval in digital libraries
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
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
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 tree


each node may have a label, data record, both
or 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
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
1.3 Replicated files

• When dealing with multiple servers and multiple clients, files


are replicated.
• Problems while making updation – handled by
1. 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
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
Three basic types of messages
- mail boxes • User message
- distribution list • Replies
• Probes
Originator’s Recipient's
terminal terminal

User P2 User
Agent Agent
P3 P7 P3 P7

MS Message MS
Message Transfer Message
Transfer Agent Agent Transfer Agent

Presentation Layer

P1 P1

Message Transfer System


3. Virtual Terminals

Terminal
(Monitor & Keyboard)
Local Host

Network
Network

Terminal Local Host Remote Host


(Monitor & Keyboard)
Operating Operating
system system
Terminal
(Monitor & Keyboard)

VT VT
structure Network structure software
software Network

Terminals falls in three broad classes


1.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 each
3.Form mode – have built-in microprocessors – used in applicaions like banking,
airline reservations etc
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
5. Teletext
6. Videotex
• Refer P.Nos. 574-576 : Andrew S. Tanenbaum,
Second Edition

You might also like