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.

Chapter 1 ■ Introduction to Cryptography and Python 7

import matplotlib.mlab as mlab

import matplotlib.pyplot as plt

mu, sigma = 100, 15

x = mu + sigma*np.random.randn(10000)

# the histogram of the data

n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green',

alpha=0.75)

# add a 'best fit' line

y = mlab.normpdf( bins, mu, sigma)

l = plt.plot(bins, y, 'r--', linewidth=1)

plt.xlabel('Smarts')

plt.ylabel('Probability')

plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')

plt.axis([40, 160, 0, 0.03])

plt.grid(True)

plt.show()

Save the file as matplot.py and execute the file. The preceding Python recipe

will generate a plot using NumPy and the Matplotlib library (see Figure 1.2).

Figure 1.2: Matplot.py test

Installing the Cryptography Package

Python has a Cryptography package that provides cryptographic recipes and

primitives to Python developers. It is designed to be your “cryptographic standard

library.” As of this writing, it supports Python 2.7, Python 3.4+, and PyPy

5.4+. You can install the Cryptography package by using Pip3. The syntax is

as follows:

$ pip3 install cryptography

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

Saved successfully!

Ooh no, something went wrong!