Fall 2026
  • Discord
  • Gradescope
  • Syllabus

On this page

  • Start
  • Decode and convert
  • Check and submit

Lab: Decode and Convert

Due: Wednesday, September 30 at 11:59pm · Worth: 6 points

An encoding tells a program how to read the bytes in a text file. You’ll recover a message by finding its encoding, then write a function that converts files from a known encoding to UTF-8.

Start

Download and extract the starter ZIP. Open the inner lab-files folder and publish your repository as lab-files.

Open decode_dossier.py, convert_files.py, and the samples/ folder. The runner in convert_files.py lists the encoding for each sample file.

Decode and convert

Start with part2/secret_message.txt. Use decode_dossier.py to read its bytes and try encodings until the Portuguese text is readable. Save the decoded message as UTF-8. Use the reading’s file examples for reading and writing text.

Complete convert_file(source, destination, encoding) in convert_files.py. Read the source using the supplied encoding and write the same text to the destination using UTF-8. Keep the original files for testing.

Decode the message

Use decode_dossier.py to inspect the bytes and try encodings. The message is Portuguese, so start with the Western European entries in the Python codecs table. Submit the Portuguese text, not a translation or a printed bytes representation.

  • Decode part2/secret_message.txt into its original Portuguese text, preserving accents and punctuation.

  • Save the result at exactly part2/secret_message.utf8.

  • Encode the saved file as UTF-8.

Convert the files

  • Implement convert_file so files in the supplied encoding become UTF-8 files with exactly the same text.

  • Preserve the source file and replace existing destination contents when rerunning the converter.

Check and submit

Run:

python convert_files.py

Open converted/cafe.txt, converted/notes.txt, and converted/greeting.txt as UTF-8. You should see Café: crème brûlée, 今日の予定, and Olá, Maya!. Check that the recovered Portuguese message also keeps its accents and punctuation. Run the converter again to check that it replaces the output rather than appending a second copy.

Commit convert_files.py, decode_dossier.py, and part2/secret_message.utf8, keeping the starter’s sample inputs. Submit lab-files and your working branch on Gradescope. The grader checks the recovered message and runs your converter on different text files. You don’t need to submit converted/.