Penguin Fortress YouTube Channel

Introduction to Cryptography

Introduction to Cryptography Part 1 - History of Encryption, Understanding Ciphers and the ROT13 cipher

Cryptography is used to protect information, to guarantee it's not been tampered with and a way to prove the original source of the information.

The word Cryptography comes from ancient greek. Kryptos – meaning hidden secret, and graphey meaning to write. A way to turn some readable information (plaintext) to unintelligible nonsense (ciphertext). Whilst text is used in this definition, it doesn’t need to be text and could be any information that needs to be hidden, such as images or other binary data.

In the first video on Cryptography I discuss some historical moments in cryptography, explain about the terminology, show how the Caesar Shift Cipher works, how ROT13 can be used to obfuscate punchlines on forums and how to create your own ROT13 encryption in Python.

Transcript: Introduction to Cryptography part 1 - Video Transcript

Alice, Bob and Eve

The diagram below introduces fictional characters used in cryptopgrahy explanations. Alice is the one wanting to send a protected message. Bob is the intended recipient who wants to read the messages. Eve is trying to evesdrop on the message to find out what Alice is telling Bob.

Cryptography fictional characters Alice, Bob and Eve

These are commonly used as fictional characters when discussing cryptography. You will often see them in other explanations and academic papers, so it makes sense to continue to use those names here.

ROT13 implementation in Python

The code below shows how you can create ROT13 encryption algorithm in Python. It's not actually needed as the Python library 'codecs' already includes an implementation of the library, but this demonstrates how it could be achieved.



while True:

    print ("Please enter a string to encrypt or decrypt")

    print ("or a blank string to quit")



    plaintext = input()

    ciphertext = ""



    # If empty string exit

    if (plaintext == ""):

        break



    for pt_chr in plaintext:

        # Check if it's an alpha character (otherwise leave unchanged)

        # convert to a number

        pt_int = ord(pt_chr)

        if (pt_int >= ord('A') and pt_int <= ord('Z')):

            # it's upper case

            # add 13

            ct_int = pt_int + 13

            # check to see if we need to wrap around

            if ct_int > ord('Z'):

                ct_int -= 26

            ciphertext += chr(ct_int)

        elif (pt_int >= ord('a') and pt_int <= ord('z')):

            # it's  lower case

            # add 13

            ct_int = pt_int + 13

            # check to see if we need to wrap around

            if ct_int > ord('z'):

                ct_int -= 26

            ciphertext += chr(ct_int)



        else:

            # not alpha char so just add

            ciphertext += pt_chr



    print ("Resulting text is:")

    print (ciphertext)

    print ("")

The code is only 40 lines long and some of those are comments, empty lines or print statements.

Note that this isn't necessarily the most efficient way of doing this, but it’s been broken down step by step so that you can see what happens.

I've also created a GUI application for this which is on my sister site PenguinTutor - Creating a GUI app using Guizero - ROT13 encryption.

Introduction to Cryptography Part 2 - Asymmetric vs Symmetric Encryption

In part two of my video I explain about how cryptography can be used to secure communications. It looks at symmetric and asymmetric key based algorithms and how they are used in different circumstances. It also covers digital signatures and how to provide the message came from who it claimed.

Transcript: Introduction to Cryptography part 2 - Video Transcript

Introduction to Cryptography Part 3 - Modes of Operation

In part three I look at Cryptographic Modes of Operation.

Transcript: Introduction to Cryptography part 3 - Video Transcript

This covers

  • Electronic Code Book Mode (ECB)
  • Cipher Block Chaining Mode (CBC)
  • Cipher Feedback Mode (CFB)
  • Output Feedback Mode (OFB)
  • Counter Mode (CTR)
  • Galois / Counter Mode (GCM)
  • Counter with Cipher Block Chaining Message Authentication Code Mode

The video explains how these are used with relevant encryption and decryption algorithms, looking at block and streaming based ciphers.

More information

Please subscribe to Penguin Fortress on YouTube for future videos.

For more details about how security see the following guides:

Previous CIA Triad
CIA Triad