Symmetric encryption · 03 The maths

Symmetric encryption: the maths

XOR and its properties, the size of the key space, brute force and the problem of the number of keys among many users.

XOR

The most used operation in symmetric encryption is XOR (exclusive or): it compares two bits and returns 1 if they are different, 0 if they are equal.

ABA XOR B
000
011
101
110

It has a valuable property: applying the same XOR twice returns the original value. If C = P XOR K, then C XOR K = P. Encrypting and decrypting are the same operation.

How many keys are needed

  1. 01
    Key space

    An n-bit key has 2^n possible values: 2^56 for DES, 2^128 for AES-128.

  2. 02
    Brute force

    Trying a trillion keys per second, 2^56 keys take about 20 hours; 2^128 take about 10^19 years, almost a billion times the age of the universe.

  3. 03
    Keys between users

    For n people to communicate in pairs with different keys, n(n − 1)/2 keys are needed: 45 for 10 people, 4,950 for 100, almost 500,000 for 1,000.

Continue with
04 Worked example

Symmetric encryption: worked example

An example of XOR encryption on a single character and on a word, to see how the same key encrypts and decrypts.

↑