Professional Documents
Culture Documents
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
i) Substitutional
ii) Transpositional
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
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
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
• 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
User P2 User
Agent Agent
P3 P7 P3 P7
MS Message MS
Message Transfer Message
Transfer Agent Agent Transfer Agent
Presentation Layer
P1 P1
Terminal
(Monitor & Keyboard)
Local Host
Network
Network
VT VT
structure Network structure software
software Network