UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 7.5 Free with a free account
The Presentation Layer
Introduction to Operating Systems · Chapter 7: Computer Networks: Architecture, Layers, and ProtocolsSection 7.5 · lesson 60 of 838 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: The Transport Layer →← The Network Layer and IPNext lesson: The Transport Layer →
A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →
In this lesson
How data is encoded, compressed and encrypted before it travels.
- Explain the presentation layer's three jobs: encoding, compression and encryption
- Count the UTF-8 bytes in text with accented letters and explain garbled characters
- Apply run-length encoding and explain why random data does not compress
- Compare symmetric and public-key encryption and explain why toy ciphers are weak
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,095 words). Read along, or search it.
Opening Puzzle
A Garbled Crème Brûlée Order
A customer abroad orders a crème brûlée cupcake from Sam, who runs a small online bakery. But on Sam's screen, the order reads like this. Nothing was lost on the wire. Both computers read the same bytes, but with two different tables. The presentation layer exists to prevent mix-ups like this. It also shrinks data, and keeps it private, on its way.
Three Jobs
Encode, Compress and Encrypt
Layer 6, the presentation layer, takes what the application wants to say, and makes it fit to travel. Think of mailing a gift. You write the note in a language the reader knows: that's encoding. You vacuum-pack the gift so it takes less room: compression. And you lock it in a box: encryption. The receiver undoes the three jobs in reverse: decrypt, decompress, then decode. In the real world, the TCP/IP model has no separate presentation layer. Apps and libraries do these jobs, like a browser decoding text.
Character Encoding
ASCII, Unicode and UTF-8
Start with encoding. A network carries only bits, so every letter must become a number. A character encoding is the agreed table. The old table, ASCII, has 128 characters: English letters, digits, punctuation and some control codes. It has no room for accents, other alphabets, or emoji. Unicode gives every character in the world's writing systems its own number. And UTF-8, the most common way to write those numbers as bytes, uses one byte for each ASCII character, and two, three or four for the rest.
Worked Example
Five Bytes for Four Letters
Here's a short Python program that encodes the word café, accent and all. It turns the word into UTF-8 bytes, prints each letter with its number and its bytes, then reads the bytes back with two different tables. Run it. Four letters. The plain letters c, a and f take one byte each: 99, 97 and 102. But é is number 233, and UTF-8 writes it as two bytes: 195, then 169. So four letters need five bytes. Read back as UTF-8, the word is fine. But read the same bytes with the Latin-1 table, and é turns into two odd symbols. That's Sam's bug, in miniature. And the last line says café isn't pure ASCII: 233 is past ASCII's last code, 127. Now change one thing. Make the word crème, and run it again. Five letters, six bytes. And the Latin-1 reading turns è into the same kind of garble, the one Sam saw on screen.
Quick Check
Counting Bytes in Jalapeño
Quick check. Sam adds jalapeño cornbread to the menu. This program counts the letters, and the UTF-8 bytes, of the word jalapeño. How many bytes: eight, nine, or sixteen? Pause and predict. Nine. Seven plain letters take one byte each, and ñ takes two. Eight is the trap: it counts letters, not bytes. When a limit is in bytes, like a text field or a packet, accented letters and emoji take more than one.
Compression
Lossless Versus Lossy
Next job: compression. Data on a network costs time, so smaller is better. Compression removes repetition, so the same information takes fewer bytes. It's lossless when the original comes back exactly, as with ZIP files and text. It's lossy when some detail is thrown away for good, as with many photo, music and video formats.
Run-Length Encoding
Counting Runs of the Same Value
The simplest lossless method is run-length encoding: store each run of the same value as a count, then the value. This function walks along the text. For each run, it finds where the same letter stops, then writes down the count and the letter. The row is one line of a black and white picture: ten white, four black, then ten white. Run it. Twenty-four characters become just eight.
Quick Check
Do Not Forget the Last Run
Quick check. Here's a new row, for the same function. What will it print for this row? Pause and predict. 3B8W1B: three B, eight W, one B. The count comes first, then the value. 3B8W forgets the last run. That single B at the end is a run too, a run of one.
Real Compressors
DEFLATE Shrinks Repeats, Not Randomness
Real compressors are cleverer. Python's zlib uses DEFLATE, the method inside ZIP files, which replaces repeats with short references to earlier text. Sam's menu repeats the same three words sixty times: thirteen hundred eighty bytes. Run it. The menu shrinks to just forty-four bytes, and unzips to exactly the original. But random bytes have no pattern to remove. A thousand of them don't shrink at all. They even grow a little, to one thousand eleven. That's why data is compressed before it's encrypted. Encrypted data looks random, so there's nothing left to squeeze.
Encryption
Symmetric and Public-Key Encryption
The third job is encryption: scrambling data with a key, so only someone with the right key can read it. The readable original is the plain text. The scrambled result is the cipher text, and that's all a listener on the wire can see. In symmetric encryption, both sides share one key. In public-key encryption, two linked keys work as a pair: one locks, and the other unlocks. So strangers can send locked messages without swapping a secret first. Web addresses that start with https use both kinds together. Lesson 8.7 says more.
Toy Cipher
A Shift Cipher With Only 26 Keys
Here's a toy, just to show the idea of a key. It shifts each letter along the alphabet by the key. Never use it for anything real. It seals Sam's order with key 3, then tries the right key, and a wrong one. Run it. The cipher text is gibberish. The right key brings the order back, and the wrong key gives more gibberish. But this toy is weak. A shift cipher has only 26 keys, so an eavesdropper can simply try them all, in seconds.
Real Ciphers
AES and Trusted Libraries
Real ciphers, like AES, use keys of 128, 192 or 256 bits: far too many to try. Their designs are public, and checked by experts. So use a trusted library, and never invent your own.
Real Example
Switching the Shop to HTTPS and UTF-8
Back to Sam. Customers sometimes send phone numbers with their orders. So Sam asked Ivy, who looks after the computers at a school: can anybody read those on the wire? On plain http, yes, Ivy said. On https, the data is encrypted before it leaves, so a listener sees only noise. Sam switched the shop to https that afternoon. And the crème brûlée? The fix is agreement. The shop's pages now declare UTF-8, so both sides read the bytes with the same table.
Key Takeaways
Same Table, Smaller Data, Locked Data
To recap. The presentation layer has three jobs: encode, compress and encrypt, undone in reverse at the other end. UTF-8 writes plain letters in one byte, and others in two to four. Both sides must use the same table. Lossless compression removes repetition, but random data won't shrink. And encryption locks data with a key. Use real, tested ciphers, never toys.
About Introduction to Operating Systems at UPI Study
Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
Where the credit goes
Universities that work with NCCRS
Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About The Presentation Layer
What is the difference between ASCII and UTF-8?
Why do accented letters show up as strange symbols?
What is the difference between lossless and lossy compression?
Why is data compressed before it is encrypted?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Introduction to Operating Systems.
83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →