WeCodeAcademy

Symmetric Encryption: One Shared Key

Symmetric encryption uses the same key to lock and unlock. Modern standards such as AES do this extremely well and fast, so they protect files, disks and the bulk of web traffic.

The XOR operation shows the core idea. XOR-ing data with a key scrambles it; XOR-ing again with the same key restores it. A one-time pad (key as long as the message, random, used once) is unbreakable, but impractical, which is why real systems use AES with managed keys.

The hard part of symmetric encryption is sharing the key safely. That problem leads to public-key cryptography.

This code is a teaching toy. In real applications use a vetted library, never hand-written crypto.

Examplepython
Open in editor »
Quick check

What is the main difficulty of symmetric encryption?

Your turn: write the code

Lock the message with XOR using key b'Z' and print the result as hex.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.