07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2 Chapter 1 ■ Introduction to Cryptography and Python

Exploring Algorithms

The algorithms you will explore in this book can be quite sophisticated, but

most of the logic is encapsulated into little black boxes that allow you to interface

with the algorithms using functions. In the programming or mathematical

world, a function is merely a way to enter values and receive output. When using

algorithms in cryptography, we generally have two inputs for encryption and

two inputs for decryption:

■■

The encryption process will take the plaintext message (P) along with an

encryption key (K) and then run the plaintext through encryption algorithms,

which will return ciphertext (C).

■■

On the decryption side, the ciphertext (C) will be supplied along with the

encryption key (K), which will produce the plaintext (P) message.

As you study various encryption themes throughout this book, you will find

that they are described by three algorithms: GEN for key generation, ENC for

the encryption algorithm, and DEC for the decryption algorithm. You’ll revisit

this concept at the end of this chapter when you learn how to create a Python

function.

Why Use Python?

Using Python for cryptography is simpler than using languages such as C or

C++; while free libraries such as OpenSSL are available, their use can be quite

complex. Python removes these complexities with many built-in libraries that

aid in cryptography scripting. It is also a great choice because Python is free in

terms of license. Python can be described as an open-source, general-purpose

language that is object oriented, functional, and procedural, and it allows for

the interface with C/ObjC/Java/Fortran and even .NET. A number of versions

are available, from 2.5.x through 3.x. Currently, 3.x is becoming more popular

as new libraries are introduced. Python comes preinstalled with Linux and

macOS, and you can install it on Windows as well. You will learn how to install

Python in each of these environments later in this chapter.

Because Python is available for Windows, Linux/Unix, Mac, and Chromebooks,

among others, the lessons you learn here will be portable to several

environments. Python has proven to be quite powerful in information security

and can be used to quickly script solutions to help you become a better security

practitioner. If you are using Ubuntu Linux, every command you see in

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!