Rome colliseum

[Episode 1]- Beginning encryption in an easy way

hugo espinelli
3 min readDec 18, 2021

Cryptography is the science of using codes. Everyone has used some kind of secret communication code even unconscious. Whether in the simplest way, in a classroom, to communicate with your friend about a subject that other people could not know, or in a war to convey some important message to the generals.

It’s the art of creating an indecipherable message through transforming the letters. Of course these secrets don’t always remain secret. A Cryptanalyst can break into the secret code and read the encrypted message using numerous types of techniques.

This is an extremely wide field of study that involves a lot of math. There are numerous types of encryption: ROT13, Lorenz, Rail Fence, Vigenere. The easiest way to enter this world is to start with the basics. Think like the ‘Hello World’ of the world of cryptography. An easy-to-understand cryptogram is the Caesar Cipher.

Caesar Cipher

Let’s start by understanding cryptography that was created over 2000 thousand years ago. It works by swapping each letter of a message with a new letter in the alphabet following a shift order. For example, let’s encode the message ‘Hello World’ using Caesar Cipher with a shift of 2. The original message is:

Hello World

The alphabet corresponds to:

‘A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z.’

As we are using a shift of 2 spaces, the message looks like:

Jgnnq Yqtnf

That is, we shift the alphabet into 2 letter positions. What was H -> J, E -> g and so on.

source: https://www.geeksforgeeks.org/caesar-cipher-in-cryptography/

We can shift a finite amount of times since we have finite numbers of letters in the alphabet. This makes the algorithm really easy to break through brute force. And this is a type of symmetric encryption, as we can revert the encoded message to the original knowing what rules were used.

So the next time you need to send a secret message without your boss finding out, you already know how to use Caesar Cipher to encode it(Unless he’s a history major).

Pythocrypt

I made a python package called pythocrypt, an extremely lightweight package that contains some of the main encryption algorithms used for study purposes. It still contains few modules, but if you want to contribute, feel free to upload a merge request :D.

I will briefly show you how to use the package to encode or decode using Caesar Cipher.

First, let’s install the package:

pip install pythocrypt

Now an example of code to encrypt the message we commented above:

from pythocrypt import caesarmessage = "Hello World"
message_encrypted = caesar.encrypt(message) # Jgnnq Yqtnf

We can also change the shift as we want by doing:

from pythocrypt import caesarmessage = "Hello World"
message_encrypted = caesar.encrypt(message, shift=10)

And finally, we can also perform brute force through some parameters:

from pythocrypt import caesarmessage = "Jgnnq Yqtnf"
message_encrypted = caesar.brute_force_decryption(
message,
initial_shift=1,
final_shift=23,
key='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
)

Conclusion

Now that we understand the basics, we can dive into more complicated algorithms. This is the beginning of a series I plan to post about the main encryption algorithms used. The next one will probably be about Rail Fence Cipher.

--

--

hugo espinelli

Full stack developer. Game enthusiast and crazy to learn new things. Passionate about aviation.