Motivation

Are you here because you are worried that all your traffic is sniffed and analyzed by the government? You are at the right place! Here you will learn both encrypting your text and read someone’s secret chat that was encrypted with a substitution cipher.

The bad thing is that in the end, you will be sure that all your chats in WhatsApp can be easily decoded (sure this is not true, Facebook decided to not use the substitution cipher for WhatsApp around 40 years ago).

We will implement a substitution cipher in Python, and then we will try to break the code using statistics.

Substitution Cipher

Wikipedia says:

In cryptography, a substitution cipher is a method of encrypting by which units of plaintext are replaced with ciphertext, according to a fixed system; the “units” may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing the inverse substitution.

In other words, all letters “A” are substituted with “B”, and all “B”s are substituted with something else. We simply mix all letters. And the person that receives the encrypted text knows which way letters are mixed.

Let’s see an example.

#python #information-security #substitution #cipher #javascript

Substitution Cipher in Python and JS
1.95 GEEK