100% found this document useful (1 vote)
15 views

Implementing Cryptography Using Python 1st Edition Shannon Bray pdf download

The document provides information about various ebooks available for download, including titles on cryptography, programming, and historical topics. It highlights the book 'Implementing Cryptography Using Python' by Shannon Bray, detailing its contents and the author's background. The document also includes acknowledgments and a brief overview of the book's structure and chapters.

Uploaded by

stearhadyaej
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
15 views

Implementing Cryptography Using Python 1st Edition Shannon Bray pdf download

The document provides information about various ebooks available for download, including titles on cryptography, programming, and historical topics. It highlights the book 'Implementing Cryptography Using Python' by Shannon Bray, detailing its contents and the author's background. The document also includes acknowledgments and a brief overview of the book's structure and chapters.

Uploaded by

stearhadyaej
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Implementing Cryptography Using Python 1st

Edition Shannon Bray download

https://ebookname.com/product/implementing-cryptography-using-
python-1st-edition-shannon-bray/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Implementing SOA Using Java EE 1st Edition B.V. Kumar

https://ebookname.com/product/implementing-soa-using-java-ee-1st-
edition-b-v-kumar/

Beginning Python Using Python 2 6 and Python 3 1 Wrox


Programmer to Programmer James Payne

https://ebookname.com/product/beginning-python-using-
python-2-6-and-python-3-1-wrox-programmer-to-programmer-james-
payne/

Python High Performance Programming Boost the


performance of your Python programs using advanced
techniques 1st Edition Gabriele Lanaro

https://ebookname.com/product/python-high-performance-
programming-boost-the-performance-of-your-python-programs-using-
advanced-techniques-1st-edition-gabriele-lanaro/

Adventures in the Bone Trade The Race to Discover Human


Ancestors in Ethiopia s Afar Depression 1st Edition Jon
Kalb (Auth.)

https://ebookname.com/product/adventures-in-the-bone-trade-the-
race-to-discover-human-ancestors-in-ethiopia-s-afar-
depression-1st-edition-jon-kalb-auth/
Poverty and Charity in the Jewish Community of Medieval
Egypt Mark R. Cohen

https://ebookname.com/product/poverty-and-charity-in-the-jewish-
community-of-medieval-egypt-mark-r-cohen/

Insurance and the law of obligations 1st ed Edition


Merkin

https://ebookname.com/product/insurance-and-the-law-of-
obligations-1st-ed-edition-merkin/

Overlay Crochet Jewelry Melody Macduffee

https://ebookname.com/product/overlay-crochet-jewelry-melody-
macduffee/

M36 M36B 1 Tank Destroyer 1st Edition David Doyle

https://ebookname.com/product/m36-m36b-1-tank-destroyer-1st-
edition-david-doyle/

International Law and Post Conflict Reconstruction


Policy 1st Edition Matthew Saul (Editor)

https://ebookname.com/product/international-law-and-post-
conflict-reconstruction-policy-1st-edition-matthew-saul-editor/
Oxford English for Information Technology Teacher s
Book Eric H. Glendinning

https://ebookname.com/product/oxford-english-for-information-
technology-teacher-s-book-eric-h-glendinning/
Implementing
Cryptography Using
Python®
Shannon W. Bray
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com

Copyright © 2020 by John Wiley & Sons, Inc., Indianapolis, Indiana


Published simultaneously in Canada

ISBN: 978-1-119-61220-9

ISBN: 978-1-119-61222-3 (ebk)

ISBN: 978-1-119-61545-3 (ebk)

Manufactured in the United States of America

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or
by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted
under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission
of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clear-
ance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the
Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111
River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/
go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or war-
ranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all
warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be
created or extended by sales or promotional materials. The advice and strategies contained herein may not
be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in
rendering legal, accounting, or other professional services. If professional assistance is required, the services
of a competent professional person should be sought. Neither the publisher nor the author shall be liable for
damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation
and/or a potential source of further information does not mean that the author or the publisher endorses
the information the organization or website may provide or recommendations it may make. Further, readers
should be aware that Internet websites listed in this work may have changed or disappeared between when
this work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department
within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included
with standard print versions of this book may not be included in e-books or in print-on-demand. If this book
refers to media such as a CD or DVD that is not included in the version you purchased, you may down-
load this material at http://booksupport.wiley.com. For more information about Wiley products, visit
www.wiley.com.

Library of Congress Control Number: 2020940306

Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc.
and/or its affiliates, in the United States and other countries, and may not be used without written permis-
sion. Python is a registered trademark of Python Software Foundation. All other trademarks are the property
of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned
in this book.
To Stephanie, Eden, Hayden, and Kenna,
with all my love, for making each and every day special.
About the Author

Shannon W. Bray started his career in information technology in 1997 after


being honorably discharged from the United States Navy. He started his IT
career working on programmable logic controllers out in the Gulf of Mexico
and then started writing business applications using various technologies until
2000 when .NET was first released; since then, the languages of choice have
been C++, C#, Windows PowerShell, and Python. From there, Shannon worked
on writing software until he started working with Microsoft SharePoint. The
Microsoft stack of technologies forced Shannon out of just writing code into
building large secure solutions. Shannon’s career has taken him to engagements
all over the world where he has worked with a number of U.S. government
agencies. Shannon became interested in cryptography while pursuing a master’s
degree in cybersecurity, and he has continued to research cryptography and
cybersecurity as he pursues a PhD in computer science.
Shannon has earned the following certifications: Microsoft Certified Master,
Microsoft Certified Solutions Master, Certified Information Security Manager
(CISM), Security+ (Plus), the CompTIA Advanced Security Practitioner (CASP+),
and a number of other industry certifications. In addition to writing, Shannon
speaks nationally at technology conventions and works as a mentor teaching
technology to youth programs.
Shannon lives in the Raleigh, North Carolina, area with his wife, Stephanie,
two daughters, Eden and Kenna, and son, Hayden. During the dive season,
Shannon enjoys diving off the coast of North Carolina. During the rest of the
year, Shannon works on IT projects around the house that utilize single-board
computers and, most often, propellers. He is currently building a home security
system that uses Python, cryptography, and drones. As of the release of this

v
vi About the Author

book, Shannon is currently running for the U.S. Senate for the state of North
Carolina to help bring cybersecurity issues to the mainstream and to help people
understand the importance of end-to-end encryption.
Shannon can be contacted through LinkedIn at www.linkedin.com/in/
shannonbray.
Acknowledgments

While this is my third book, every book comes with its own set of challenges.
Completing a book is not always a fun project but does become a labor of love.
As soon as you start, life has a way of throwing changes at you, and it seems
that you never have the time that you thought you would have. Shortly after
starting this book, I started a PhD program with the Missouri University of
Science and Technology and transitioned through a number of government
contracts, ran for political office, and then became a work-from-home teacher
as the world battled a global pandemic. I knew that the editing team would be
earning their pay with whatever I put together. That team has been wonderful
with their feedback and responsiveness. Specifically, I’d like to thank the follow-
ing people on the Wiley team: Barath Kumar Rajasekaran, production editor;
Jim Minatel, acquisitions editor; Pete Gaughan, content enablement manager;
Brent Cook and James Langbridge, technical editors, and, most importantly,
Kim Wimpsett, the project editor. Kim did her best to keep me on schedule, but
I found new ways to miss a few deadlines.

vii
Contents at a Glance

Introductionxvii
Chapter 1 Introduction to Cryptography and Python 1
Chapter 2 Cryptographic Protocols and Perfect Secrecy 31
Chapter 3 Classical Cryptography 65
Chapter 4 Cryptographic Math and Frequency Analysis 95
Chapter 5 Stream Ciphers and Block Ciphers 139
Chapter 6 Using Cryptography with Images 171
Chapter 7 Message Integrity 199
Chapter 8 Cryptographic Applications and PKI 223
Chapter 9 Mastering Cryptography Using Python 247
Index277

ix
Contents

Introductionxvii
Chapter 1 Introduction to Cryptography and Python 1
Exploring Algorithms 2
Why Use Python? 2
Downloading and Installing Python 3
Installing on Ubuntu 4
Installing on macOS 4
Installing on Windows 4
Installing on a Chromebook 4
Installing Additional Packages 5
Installing Pip, NumPy, and Matplotlib 6
Installing the Cryptography Package 7
Installing Additional Packages 8
Testing Your Install 9
Diving into Python Basics 9
Using Variables 10
Using Strings 11
Introducing Operators 11
Understanding Arithmetic Operators 11
Understanding Comparison Operators 13
Understanding Logical Operators 13
Understanding Assignment Operators 14
Understanding Bitwise Operators 15
Understanding Membership Operators 15
Understanding Identity Operators 16

xi
xii Contents

Using Conditionals 16
Using Loops 17
for17
while18
continue18
break18
else18
Using Files 19
Understanding Python Semantics 20
Sequence Types 20
Introducing Custom Functions 26
Downloading Files Using Python 27
Introducing Python Modules 28
Creating a Reverse Cipher 29
Summary30
Chapter 2 Cryptographic Protocols and Perfect Secrecy 31
The Study of Cryptology 32
Understanding Cryptography 32
Cryptography’s Famous Family: Alice and Bob 33
Diffie-Hellman34
Data Origin Authentication 34
Entity Authentication 35
Symmetric Algorithms 36
Asymmetric Algorithms 36
The Needham-Schroeder Protocols 36
The Otway-Rees Protocol 38
Kerberos39
Multiple-Domain Kerberos 40
X.50941
Formal Validation of Cryptographic Protocols 46
Configuring Your First Cryptographic Library 47
Understanding Cryptanalysis 47
Brute-Force Attacks 47
Side-Channel Attacks 48
Social Engineering 48
Analytical Attacks 48
Frequency Analysis 48
Attack Models 49
Shannon’s Theorem 50
One-Time Pad 51
XOR, AND, and OR 51
One-Time Pad Function 56
One-Way Hashes 58
Contents xiii

Cryptographic One-Way Hashes 59


Message Authentication Codes 60
Perfect Forward Secrecy 60
Published and Proprietary Encryption Algorithms 61
Summary62
References62
Chapter 3 Classical Cryptography 65
Password Best Practices 66
Password Storage 66
Hashing Passwords 67
Salting Passwords 67
Stretching Passwords 68
Password Tools 68
Obfuscating Data 69
ASCII Encoding 70
Base64 Encoding Text 70
Binary Data 72
Decoding72
Historical Ciphers 72
Scytale of Sparta 73
Substitution Ciphers 73
Caesar Cipher 74
ROT-1376
Atbash Cipher 77
Vigenère Cipher 77
Playfair79
Hill 2x2 83
Column Transposition 87
Affine Cipher 90
Summary93
Chapter 4 Cryptographic Math and Frequency Analysis 95
Modular Arithmetic and the Greatest Common Devisor 96
Prime Numbers 97
Prime Number Theorem 98
School Primality Test 98
Fermat’s Little Theorem 100
Miller-Rabin Primality Test 100
Generate Large Prime Numbers 104
Basic Group Theory 106
Orders of Elements 107
Modular Inverses 109
Fermat’s Little Theorem to Find the Inverse 110
Extending the GCD 111
Euler’s Theorem 111
xiv Contents

Pseudorandomness115
Breaking C’s rand() Function 116
Solving Systems of Linear Equations 117
Frequency Analysis 120
Cryptanalysis with Python 123
Using an Online Word List 125
Determining the Frequency 126
Breaking the Vigenère Cipher 129
Summary138
Chapter 5 Stream Ciphers and Block Ciphers 139
Convert between Hexdigest and Plaintext 140
Use Stream Ciphers 141
ARC4147
Vernam Cipher 148
Salsa20 Cipher 149
ChaCha Cipher 151
Use Block Ciphers 156
Block Modes of Operations 158
ECB Mode 158
CBC Mode 159
CFB Mode 160
OFB Mode 162
CTR Mode 163
Tricks with Stream Modes 164
DIY Block Cipher Using Feistel Networks 165
Advanced Encryption Standard (AES) 167
Using AES with Python 167
File Encryption Using AES 169
File Decryption Using AES 169
Summary169
Chapter 6 Using Cryptography with Images 171
Simple Image Cryptography 171
Images and Cryptography Libraries 174
Understanding the Cryptography Library 174
Understanding the Cryptosteganography Library 175
Image Cryptography 175
File Cryptography Using Fernet 176
Image Cryptography Using Fernet 179
AES and Block Modes of Operations 180
Exploring a Simple ECB Mode Example 181
Exploring a Simple CBC Mode Example 185
Applying the Examples 186
Steganography187
Storing a Message Inside an Image 188
Contents xv

Storing a Binary File Inside an Image 192


Working with large images 195
Summary197
Chapter 7 Message Integrity 199
Message Authentication Codes 200
Hash-based Message Authentication Code 201
Using HMAC to Sign Message 202
Message Digest with SHA 203
Binary Digests 204
NIST Compliance 205
CBC-MAC206
Birthday Attacks 207
Crafting Forgeries 209
The Length Extension Attack 209
Setting Up a Secure Channel 210
Communication Channels 211
Sending Secure Messages over IP Networks 212
Create a Server Socket 212
Create a Client Socket 213
Create a Threaded Server with TCP 214
Adding Symmetric Encryption 215
Concatenate Message and MAC 218
Summary221
References222
Chapter 8 Cryptographic Applications and PKI 223
The Public-Key Transformation 224
Exploring the Basics of RSA 226
Generating RSA Certificates 229
Constructing Simple Text Encryption and
Decryption with RSA Certificates 231
Constructing BLOB Encryption and
Decryption with RSA Certificates 232
The El-Gamal Cryptosystem 235
Elliptic Curve Cryptography 238
Generating ECC Keys 240
Key Lengths and Curves 241
Diffie-Hellman Key Exchange 242
Summary245
Chapter 9 Mastering Cryptography Using Python 247
Constructing a Plaintext Communications Application 248
Creating a Server 248
Creating the Client 250
Creating the Helper File 251
Execution252
xvi Contents

Installing and Testing Wireshark 253


Implementing PKI in the Application Using RSA Certificates 255
Modifying the Server 256
Modifying the Client 257
Modifying the Helper File 258
Execution259
Implementing Diffie-Hellman Key Exchange 261
Modifying the Server File 262
Modifying the Client File 264
Modifying the Helper File 266
Creating the Diffie-Hellman Class File 270
Execution275
Wrapping Up 276
Index277
Introduction

I initiated my journey into cryptography while studying for my undergrad. Most


of the cryptography concepts I learned were based on what one would need for
their CISSP or Security+ exams. Most of my understanding was at a high level,
and it was difficult to remember the more intricate aspects until cryptography
became a primary focus.
It wasn’t until I started my master’s in cybersecurity that I began applying
cryptographic features within a scripting environment. The concepts in this
book will help you advance your knowledge and experience as you dig deeper
into understanding the use of cryptography in Python.
Over the past few years, several governments have discussed legislation that
will ensure that any form of communication, whether it’s an email, text message, or
video chat, can always be read by the police or intelligence services if they have a
warrant. Governments are putting pressure on technology companies to give them
backdoor access or the keys to the kingdom so that they can keep the country safe.
The fight between lawmakers and encrypted messaging platforms has entered
new territory. Imagine a world where the government has seized the oppor-
tunity to scan every electronic message by government-approved scanning
software. The privacy and security of all users will suffer if law enforcement
agencies achieve their dream of breaking cryptosystems. Proponents of end-to-
end encryption, like Microsoft, Facebook, and Google, may lose their campaign
to maintain user security as a priority.
We have all heard of times when it would be beneficial for encrypted data
to magically become readable; this is often related to criminal cases. Should
criminals be allowed to plot their plans in secret? Where does the right to our
privacy start? In reality, there are technical and legal issues with allowing gov-
ernments to do this; this of course will be strongly opposed by technology and

xvii
xviii Introduction

privacy advocates. The world is at war on what can be encrypted, what should be
encrypted, and who should have the keys to unlock someone else’s encryption.
Whether you agree or disagree with what powers a nation-state should have
over encrypted communications in their country, you should understand what
encryption is, how to apply it when needed, and how to ensure that the data
you are receiving is authentic and confidential. Over the course of this book,
you will get a basic understanding of how to cryptographically secure your
messages, files, or Internet traffic using easy-to-understand Python recipes that
have been created or updated to support Python 3.

What This Book Covers


This book focuses on helping you pick the right Python environment for your
needs so that you can hit the ground running. You will get an understanding
of what algorithms are and explore the basics of Python.
Once you have an idea of where you are starting from, you will get an over-
view of what cryptography is, what perfect secrecy means, and the history of
cryptography and how its use changed our world.
To get a full understanding of some of the cryptographic concepts, a little
math is needed. You will get an understanding of how prime numbers, basic
group theory, and pseudorandom number generators help build cryptographic
solutions. This will build the foundation for understanding various stream and
block ciphers and highlight some of their encryption modes and weaknesses.
Every cryptographic discussion is better with pictures, so we will spend a
chapter focusing on how image cryptography and steganography work. We’ll also
highlight a few issues that you will need to be aware of while dealing with images.
Message integrity is just as important as message secrecy. Knowing who sent
the message to you directly relates to whether the message is credible. You will
learn how to generate message authentication codes to ensure integrity during
transit.
The strength of encryption will be shown at the end of the book when you
will learn about PKI schemes and explore how to implement elliptic curve cryp-
tography in an application. The application you build will exchange data in a
highly secure format over an unsecure channel, thus ensuring that you are able
to control your own end-to-end encryption scheme that no one will be able to
decrypt without the keys you create. I hope you find the journey as fun as I did.
Introduction xix

What You Need to Know


This book assumes that you are fairly new to cryptography. While there is a
brief introduction to how to set up and use Python, you will get the most out of
the book if you have experience in another programming or scripting language.

What You Need to Have


The concepts presented in this book can be executed on Microsoft Windows,
Linux, Chromebook, or iOS. Your choice of editor will most likely depend on
the underlying operating system, although most of the Python recipes presented
here will execute in online editors as well as most shells that are using a Python
interpreter that is 3.0 or greater.

How to Use This Book


The topics in this book get more advanced as you progress through it, so you
can work through the material from front to back and build your skills as you
go. You can also use this book as a reference that you can consult when you
need help with the following situations:
■■ You’re stuck while trying to figure out how to secure your data.
■■ You need to do something using cryptography that you’ve never
done before.
■■ You have some time on your hands, and you’re interested in learning
something new about Python and cryptography.
The index is comprehensive, and each chapter typically focuses on a single
broad topic. Don’t be discouraged if some of the material is over your head.
As you work through the coding samples and build out the final solution, the
concepts should become easier to understand.

What’s on the Website


Nearly everything discussed in this book has examples with it. You can (and
should) download the many useful examples included with this book. We have
verified that each file will run in environments that are Python version 3.0 and
higher.
The files are located at github.com/braycrypto/cryptography, as well as at
www.wiley.com/go/cryptographywithpython.
CHAPTER

1
Introduction to Cryptography
and Python

Cryptography is one of the most important tools we have at our disposal as


information security professionals. It provides us with the ability to protect
sensitive information from unauthorized disclosure through encryption. Cryp-
tography is the use of mathematical algorithms that can be used to transform
data either into an encrypted form (ciphertext) or into its decrypted form (plain-
text). The purpose of these algorithms can be quite complicated. The goal of this
book is to help simplify the use of cryptography using the available libraries
in Python, so you will begin your journey into cryptography by setting up a
Python environment. You’ll also get a review of using Python, and then you’ll
write your first cipher using Python. Specifically, you’ll do the following:
■■ Gain an understanding of algorithms
■■ Explore various Python installations
■■ Set up Python 3 on various machines
■■ Explore the basics of the Python language
■■ Write your first cipher using Python

1
Implementing Cryptography Using Python®, First Edition. Shannon W. Bray.
© 2020 John Wiley & Sons, Inc. Published 2020 by John Wiley & Sons, Inc.
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 inter-
face 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 algo-
rithms, 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 Chrome-
books, 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 secu-
rity practitioner. If you are using Ubuntu Linux, every command you see in
Chapter 1 ■ Introduction to Cryptography and Python 3

this book will work. If you are on a Mac, you can use the Terminal app found
inside the Utilities folder. On a Windows machine, you have several options
as well: you can install a number of tools such as Cygwin, Visual Studio, or
PyCharm; use the Windows 10 Linux subsystem; or just install Ubuntu Linux
from the Microsoft Store. If you are new to Linux, I recommend practicing your
command-line skills a bit to help get you comfortable.
When you start the Python shell (by typing python or python3 at the command
line), you will see the version and the date associated with the version. For in-
stance, if you install and run Python in a Linux environment, you should see
something similar to the following:
Python 3.7.4+ (default, Sep 4 2019, 08:03:05)
[GCC 9.2.1 20190827] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

The majority of Python interpreters use >>> as a prompt to accept user input;
one notable exception is IPython, which is discussed briefly in a moment. Once
you are in a Python shell, exit by pressing CTRL+D or typing exit(). Python
files use a .py extension, and we start their execution in Linux environments
by typing python3 filename.py; (keep in mind that you still need to chmod
+x the file).

N OT E In Unix-like operating systems, the chmod command sets the permissions


of files or directories.

As you will learn later in this chapter, a large number of modules are avail-
able for Python, many of which we will use along your journey of learning
cryptography. One of the more notable modules you will learn more about is
NumPy. NumPy offers numerical operations to Python, including fast multi-
dimensional array operations, random number generation, and linear algebra.
Another module that you will be introduced to is Matplotlib, which is an excel-
lent library for plotting. In Chapter 6, you will learn more about PyFITS, which
is a module that provides access to Flexible Image Transport System (FITS) files.
FITS is a portable file standard that is widely used throughout the astronomy
community to store images and tables. We will be combining it with our cryp-
tography techniques to encrypt and decrypt image files.

Downloading and Installing Python


You can download the Python interpreter from www.python.org/python, where
you’ll find versions for Ubuntu, macOS, and Windows. Be sure to download
version 3.7 or higher, since Python 2 is now unsupported.
4 Chapter 1 ■ Introduction to Cryptography and Python

Installing on Ubuntu
If you are running Ubuntu, install Python from the Ubuntu Software Center
using these steps:
1. Open the Ubuntu Software Center.
2. In the search box in the top-right corner of the window, type Python.
3. Select IDLE.
4. Click Install.

Installing on macOS
If you are using macOS, download the .dmg file for your version of macOS and
execute it. When the DMG package opens, do the following:
1. Double-click the Python package file (.mpkg).
2. Click Continue through the Welcome section and click Agree to accept
the license.
3. Select HD Macintosh and click Install.

Installing on Windows
If you are using Windows, download and run the Python installer; it should
have an .msi extension. Then follow these steps:
1. Click Install Now to begin the installation.
2. When the installation completes, click Close.
Notice the mention of upgrading. You can upgrade a package by clearing out
the Search PyPI and Installed Packages search box. This will show you all of
the installed packages. Any package that has an update will have an up arrow
next to it along with the newer version number (see Figure 1.1). You may have
to elevate your privileges.

Installing on a Chromebook
New Windows and Chrome OS computers give you the ability to install Linux.
The Chrome OS, which is becoming more popular, enables you to install a Linux
container that you can interact with but also keeps the rest of the environment
isolated so that you do not have to worry about messing up your system.
Chapter 1 ■ Introduction to Cryptography and Python 5

Figure 1.1: Upgrading packages

To get started with Python 3 on a Chromebook, click the time in the lower-
right corner. If you have the appropriate permissions on the Chromebook, you
should see a Settings button that looks like a flower with a dot in the middle
of it. Once you are in Settings, you can scroll down until you find Linux (Beta)
and then enable it by clicking Turn On. It may take several minutes, but once
it is complete, you will be able to run Linux tools, editors, and IDEs on your
Chromebook. To continue with the Chromebook installation, see the next sec-
tion for instructions on how to install NumPy and Matplotlib.

Installing Additional Packages


Many of the coding recipes that you will find in this book require additional
packages or modules to help reduce the amount of code you need to write to
ensure message security. Most Python interpreters use a command-line approach
of loading the packages. Integrated development environments (IDEs) may have
unique ways of loading packages for each interpreter available.
6 Chapter 1 ■ Introduction to Cryptography and Python

Installing Pip, NumPy, and Matplotlib


Ensure you are in a command shell environment with a prompt. In the follow-
ing example installation, you will get an update to the packages that come with
your Python version.
Pip, or Pip3 in this case, is the package management system for Python; it is
used to install and manage software packages written in Python. Pip is similar
to tools like Bundle, NPM, and Composer in other programming languages.
NumPy, which stands for Numerical Python, is a Python package that is the
core library for scientific computing. It contains a powerful n-dimensional array
object, and provides tools for integrating C, C++, and many other languages.
Matplotlib is an excellent solution for scientific plotting; it has the ability to be
automated and produce a wide variety of customizable high-quality plots.
Once the shell is open, type the following commands:
~$ sudo apt-get update
~$ sudo apt install python-pip
~$ pip3 install numpy
~$ pip3 install matplotlib

~$ $ python3 -c "import numpy as np; import matplotlib.pyplot as plt; x


= np.linspace(0, 2 * np.pi); y = np.sin(x); plt.plot(x, y); plt.show()"

N OT E Depending on your environment, you may need to install python3-pip to


get Pip3 to work. On installs such as Ubuntu 16.04 on Windows, you will not be able to
install version 3 when you install python-pip.

To start the Python 3 shell, type the following:


~$ python3

You should see something similar to the following depending on the version
that is installed:
Python 3.X.X (default, date)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

To test whether you have the additional packages installed correctly, open
your favorite Python editor. If you don’t have one, you can elect to use Nano in
a Linux environment or even Notepad in a Windows environment. Type the
following:
#!/usr/bin/env python

import numpy as np
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 stan-
dard 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
8 Chapter 1 ■ Introduction to Cryptography and Python

The Cryptography package includes both high-level recipes and low-level


interfaces to common cryptographic algorithms such as symmetric ciphers, mes-
sage digests, and key derivation functions. For example, to encrypt something
with Cryptography’s high-level symmetric encryption recipe, use this:
>>> from cryptography.fernet import Fernet
>>> # Put this somewhere safe!
>>> key = Fernet.generate_key()
>>> f = Fernet(key)
>>> token = f.encrypt(b"A really secret message. Not for prying eyes.")
>>> token
'...'
>>> f.decrypt(token)
'A really secret message. Not for prying eyes.'

Installing Additional Packages


IPython is available through many providers; it is an enhanced, interactive
version of Python. IPython offers a combination of convenient shell features,
special commands, and a history mechanism for both input and output. IPython
offers a vastly improved set of functionality and flexibility; it is a fully compat-
ible replacement for the standard Python interpreter. You can install IPython
by typing the following:
sudo apt install IPython3
apt-get install python3-IPython

To use IPython, type IPython3 -h at the system command line. You can start
the shell by typing this:
~$ IPython3

You should see something similar to the following:


Python 3.5.3 (default, Sep 27 2018, 17:25:39)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python

In [1]:

Please note that you will need to pay attention to the version of Python; this
example is using Python 3.5.3, but you may see something like Python 2.x if you
did not specify IPython3. When Python 3 first came out, many libraries didn’t
exist, so many people stayed with 2.x. Python 3 has caught up and is now a
great language. There are, however, a few differences between Python 2.x and
Python 3, so if you find that some of your scripts fail, try running them using
an alternate version.
Discovering Diverse Content Through
Random Scribd Documents
Enter TOM, as Don Giovanni, with KATE as Domino.
Tom. (Advancing with Kate). Could I find one of your sex that would
be faithful, I would never rove again.
Kate. Are you sincere?—
Tom. By heaven!—I am!
Kate. Then behold the reward of your sincerity, the constancy of
your faithful Kate. (Unmasks).
Tom. Kate! oh, my dear Kate!
Enter LOGIC, as Doctor Pangloss, with JANE in Domino.
Log. (Advancing with Jane). I am an L.L.D. and A.S.S.
Jane. (Unmasks). You are indeed an A-S-S, not to have found me
out before.
Log. What! my Jenny!——
Jerry. Don’t be astonished, Bob—I’ll explain all:—Tom and I are
going to make two matches; you must make the third—form a
bunch of matches—exchange one imprisonment for another, her
arms, you dog!—’aint you up?—
Log. I’m fly—Oxford has no fellowship like this! (Embracing Jane).
Tom. (Coming down with Kate). You are right, Bob, it has not.—Well,
we have been amused by Life in London, now let us endeavour to
profit by it;—let our experience teach us to avoid its quicksands, and
make the most of its sunshine;—and in that anticipation let us hope
our kind friends will pardon Tom, Jerry, and Logic all their sprees and
rambles.

Jerry Going Back to the Country.

Three merry boys were Logic, Tom and Jerry,


And many funny larks they have seen;
Farewell, gay London, the country calls me home again,
The coach moves on—the play is done—Goodbye, Goodbye.

The White Horse Cellar, Piccadilly:—


Was now the parting scene, and the hand of the clock pointed very
near to the time for the departure of the coach. The bustle of this
place prevented the Trio from much conversation; but the separation
of such staunch pals was a trying moment to the feelings of poor
Jerry: and though he was above blubbering like a Johnny Raw, yet
his Heart was rather touched, and his ogles underwent some queer
sensations, which he endeavoured to suppress, when Coachy asked
“if all was right” and began to smack his whip.
The hearty grasps of the hand, and the good-byes were over
between Hawthorn and his pals, and Tom and Logic were only waiting
to see the coach start, when Jerry, with much eagerness of
expression, as if he had forgotten to mention the circumstance
previously, said, “my dear Coz”—but the coach was now fast rattling
over the stones, and the last broken sentence which the ear of the
Corinthian caught was, “Mention me in the kindest manner to the
lovely Sue; tell her I am only gone into training, and in the course of
a few weeks I shall most certainly return to London to enjoy a few
more sprees (which I have so unexpectedly been deprived of), and
also to have with her the pleasure of another game at romps.”
The End.

The Adelphi version of Tom and Jerry, or Life in London, was


performed ninety-three nights in succession; and its golden career
only stopped by the termination of the season. At the end of which,
Little Bob Keeley, who had made a great hit as Jemmy Green—a
character imported into the piece by Mr. W. T. Moncrieff—went with
Walbourn, the great Dusty Bob, and Cooper, who played to the life,
Little Jemmy, the cripple, to Sadler’s Wells Theatre, were Pierce
Egan’s own version was produced April 8th, 1822. Keeley was
threatened by the Adelphi lessees—Messrs. Rodwell and Jones—with
an action for breach of engagement, but the action was never
brought. In the season of 1822-3 at the Adelphi, John Reeve
—‘Glorious John!’ became Jerry Hawthorn, Mr. Brown took the part
of Jemmy Green, and several other changes in the original cast were
effected. At Christmas, 1822, Tom and Jerry was compressed so as to
admit of the production of a pantomime called Beauty and the
Beast, or, Harlequin and the Magic Rose. When the managers
announced that:—
“In consequence of the astonishing Overflows to witness the
admired Extravaganza of Tom and Jerry, or Life in London, and to
prevent, as far as possible, any unpleasant Disappointment, the
Public are respectfully informed that:—
NO PLACES, IN FUTURE CAN BE KEPT, UNLESS PAID FOR WHEN
TAKEN.
Shouts of Laughter and Applause attend each Representation of the
New Pantomime.”
When the long run of Tom and Jerry ended at the Adelphi, a
spectacular extravaganza of the same kind was produced with the
title of “Green in France,” but it did not catch the fancy of the town
like its predecessors.[34]
In 1825, Mr. Moncrieff published his dramatic version of Tom and
Jerry; or, Life in London—which he dedicated to:—
His Royal Highness, Frederick Duke of York,
May it Please Your Highness:—
The distinguished honour conferred by your Royal Highness on this
Drama, in commanding and witnessing its performance at the Adelphi
Theatre, (an honour unprecedented in the annals of the Minor Stage)
and the flattering manner in which your Royal Highness was
afterwards graciously pleased to express your high approbation of it,
emboldens me, with the most profound respect, to lay it at your
Royal Highness’s feet, and under the sanction of your illustrious
name, commit it in its present form to the world.
Having no higher pretensions than that of presenting a faithful
picture of the various scenes it pourtrays, the favourable opinion of
your Royal Highness stamps it with an authority that was alone
wanted to crown the success with which it has been received by the
Public.
Like the illustrious Haroun al Raschid, your Royal Highness is said to
have made yourself acquainted with the many coloured changes of
life; presented in the people over whom you may be one day called
to preside, by wisely throwing off the restraint of rank, and
witnessing nature in its genuine state. That the scenes I have
pourtrayed are not caricatured for the sake of dramatic effect, but
are actually those which might have been seen by any one choosing
to seek them, your Royal Highness can therefore adequately testify;
and your Royal Highness’s imprimatur will effectually ward off all the
imputations that have been cast upon my motives and veracity, by
the bigoted and envious.
I have the honour to be,
With the most profound respect and devotion,
Your Royal Highness’s
Most obedient and very humble Servant,
W. T. Moncrieff.
104, Drury Lane,
Dec. 15, 1825.
Mr. Moncrieff in his Dedication—To His Royal Highness: and in his
Preface that follows throws so much true light and shade on public
opinion—pro et con—of the period, that we deem it not only
desirable but instructive to the present generation to publish the
same in extenso.
PREFACE.
“It is scarcely necessary to observe this Drama is founded on the
“Life in London” of my friends Pierce Egan, and the inimitable
Cruickshank. Aided by Pierce’s clever illustrations to the matchless
series of plates to that work, I have in this piece, endeavoured to
put them into dramatic motion; running a connecting story through
the whole, making such modifications and amplifications, and
furnishing such reflections and results, as I deemed necessary. From
the popularity of the subject, the novelty and acknowledged truth of
the various scenes comprised in it, and the beauty of the music I
fortunately selected, this Piece obtained a popularity, and excited a
sensation, totally unprecedented in Theatrical History; from the
highest to the lowest, all classes were alike anxious to witness its
representation; Dukes and Dustmen were equally interested in its
performance, and Peers might be seen mobbing it with Apprentices
to obtain admission. Seats were sold for weeks before they could be
occupied, every Theatre in the United Kingdom, even in the United
States, enriched its coffers by performing it; and the smallest tithe-
portion of its profits, would for ever have rendered it unnecessary
for its Author to have troubled the public with any further
productions of his Muse. It established the fortunes of most of the
Actors engaged in its representation, and gave birth to many
publications and several newspapers. The success of the “Beggar’s
Opera,” the “Castle Spectre,” and “Pizarro,” sunk into the shade before
it. In the furore of its popularity, persons have been known to travel
post from the furthest parts of the Kingdom to see it; and five
guineas have been offered for a single seat.—These facts are not
recapitulated here from any feeling of egotism—the success of this
Drama, was the temporary rage of the moment, from time-serving
circumstances, and was never regarded in any other light by its
Author; they are merely noticed as curious events in theatrical
history.—With respect to the cry of immorality, so loudly raised by
those inimical to the success and plain-speaking of this piece, it is
soon answered! To say nothing of the envy of rival Theatres feeling
its attraction most sensibly in their Saturday Treasuries, those
notorious pests the Watchmen; dexterously joined in the war-howl of
detraction raised against it, and by converting every trifling street-
broil into a “Tom and Jerry row,” endeavoured to revenge
themselves for the exposè its scenes afforded of their villany and
extortion; but all in vain. In vain, too, it was the Actor’s old rivals,
the Methodists, took the alarm—in vain they distributed the whole of
the stock of the Religious Tract Society at the doors of the Theatre—
in vain they denounced “Tom and Jerry” from the pulpit—in vain the
puritanical portion of the Press prated of its immorality—in vain the
prejudices of the stiff-backed part of the Bench—the hypocritical
host of Saints cried it down, and preached woe and destruction to
those who supported it.—They but increased the number of its
followers, and added to its popularity. Vainly, too, was the Lord
Chamberlain called upon to suppress it—His Grace came one night
to see it, and brought his Duchess the next. It was nearly the same
with the Chief Magistrate of Bow Street: his experience rendered him
perfectly sensible, that, long before the appearance of “Tom and
Jerry,” young men and country gentlemen would in moments of
hilarity, sometimes exceed in their potations, be provoked into
quarrels by designing Watchmen, and consigned, for purposes of
extortion on the following morning, to His Honour, the Night
Constable; but according to the Saints’ accounts, to believe their
tales, it must be held as a point of faith, that no one, previous to the
appearance of “Tom and Jerry,” ever got into a row!—Oh, no—
drinking and all its train of follies were unknown to youth, until
inculcated into their minds by the example of “Tom and Jerry!” How
many an unsuspecting Country Cousin has been converted, in the
public newspapers, through an hour of harmless frolic, into a Jerry;
while his equally unconscious Town relation figured as a Tom, and
any honest plodder they may have had with them is transformed
into a Bob Logic—his first appearance in that character. The thing
speaks for itself: the hue and cry of the immorality and danger of
this piece was raised merely for the purposes of plunder, by
Watchmen and others. So far from being immoral, if the piece be
fairly examined, it will be found to be as correct in its tendency as
any production ever brought on the stage. The obnoxious scenes of
life are only shown that they may be avoided: the danger of mixing
in them is strikingly exemplified; and every incident tends to prove,
that happiness is only to be found in the domestic circle.
“It has been said, that many of the scenes of this piece should not
have been exhibited, being scenes of dissipation, riot, and
impropriety—ridiculous!—Has not Shakespeare asserted that the
proper use of the drama is—“to hold, as ’twere, the mirror up to
nature, to show virtue her own feature, and vice her own image,
and the very age and body of the time its form and pressure:” could
any piece do this more effectually than “Tom and Jerry?” take away
the scenes complained of, it ceases to show the form and pressure
of the age and time.
“I should not have published this piece had not its success produced
such a host of imitations and plagiarisms, that more to prevent
myself suffering from the demerits of others than to avail myself of
any merits of my own. I give it with all its imperfections on its head,
to the world; willing to pay smart blunt for my own misdeeds, but
not stand Sammy for those of others. To those venerable noodles
who complain that I and my prototype, Pierce, have made this the
age of flash; I answer any age is better than The age of cant! I tell
my pious lecturers, in plain terms, I shall always feel pleasure in
reflecting that I have in this piece, nosed every move on the board,
in the game of the spell; opened the ogles of the green and the
yokel, and the muff, and the raw; struck a light on the darky of their
knowledge boxes, flashed the gab of the prig, the leg, the scamp
and the stringer, in their listeners, put them fly and awake to all they
should be up and down to, and enabled them, if their lugs are at all
wing to the bits of good truth, pattered to them in every scene of
this piece, bank their rag, chivey their nurses, nash their leading
strings, and keep out of the way of the cut-along-coaches as they
travel the high toby of existence; and having so done, can lay my
mawley on my core, and conscienciously chaunt my conviction, in
which my reader will bear me out, “that I’ve cut all the buzmen, and
done the thing right.”
W. T. M.
104, Drury Lane,
Dec. 15, 1825.

The Dustman.

Bring out your dust the dustman cries,


Whilst ringing of his bell:
If the wind blows, pray guard your eyes,
To keep them clear and well.

Pierce Egan on Mr. Walbourn’s “Dusty Bob.”


“It is the greatest possible praise to be
praised by a man who is himself
deserving of praise.”
“Approbation from Sir Hubert Stanley is
praise indeed.”
Mr. Walbourn’s theatrical fame was made by, and, strange to say,
expired with the character of Dusty Bob. Pierce Egan, in his “Life of
an Actor,”—which he dedicated to Edmund Kean—classes his
performance of this part, as giving him a title in the niche of fame
beside John Kemble, Mrs. Siddons, and all the great actors contained
in his “Catalogues of Parts Acted”—which can never be forgotten by
those who witnessed them. Here is the note, and will be found at
page twelve of the work:—“The personification of Dusty Bob, by the
above actor, has been unanimously decided by the public to be one
of the greatest triumphs of the histrionic art ever exhibited on any
stage. The first tragedian of the day,[35] with the utmost liberality,
gave it as his opinion, that, during the whole course of his theatrical
life, he had never seen any performance equal to it. Also, a comic
actor of the greatest celebrity[36] exclaimed, ‘Good heaven! is it
possible? Do my eyes deceive me? Most certainly it is a real dustman
they have got upon the stage. I am very sorry the profession has
descended so low as to be compelled to resort to the streets to
procure a person of that description to sustain the character.’ He left
the body of the theatre in utter disgust—nor was it until introduced
to Mr. Walbourn in person, behind the scenes, that he would believe
it was an actor. Further praise than this is superfluous.”
Mr. Walbourn as “Dusty Bob,” was drawn and engraved by George
Cruikshank, and sold, with other character-portraits, at the Adelphi
Theatre. During the long run of the piece, he exchanged one species
of hops for another, as he gave up his business as a private and
stage dancing-master, and took the “Maidenhead” public-house at
Battle Bridge. The house, previous to his taking it was doing only a
small trade; but, when he became the landlord, and put out a spick-
span new and a “not so dusty” sign of himself as “Dusty Bob,”
painted in oil by George Cruikshank, it drew together many of the
“Dusty” fraternity—and their doxies. After that, “Dusty Bob,”
together with “Black Sal,” became to be bye words, as, near to the
house, was Smith’s dust-yard, at which hundreds were employed,
male and female. But:—
“A heap of dust alone remains of thee;
’Tis all thou art, and all the proud shall be!”

The Literary Dustman.


My dawning genus fust did peep,
Near Battle Bridge ’tis plain, sirs—
You recollect the cinder heap,
Vot stood in Gray’s Inn Lane, sirs?[37]
’Twas there I studied pic—turesque,
Vhile I my bread vos yarning,
And there, inhailing the fresh breeze,
I sifted out my larnin’!
They calls me Adam Bell, ’tis clear,
(As Adam vos the furst man),
And by a co—in—side—ance queer,
Vy, I’m the fust of dustmen!—
A Literary Dustman!
The “Old Pub.” of sixty years ago is now The Victoria Tavern, Great
Northern Railway. Maiden Lane is York Road, and Battle Bridge is
known as King’s Cross, from a statue of George IV.—a most
execrable performance—taken down in 1842.
Great sculptors all conwarse wi’ me,
And call my taste diwine, sirs—
King George’s statty at King’s Cross
Vas built from my design, sirs.
The Literary Dustman.
Besides the authors already mentioned. Tom Dibden, Farrell, and
Douglas Jerrold, each produced dramas upon the popular theme;
and during the seasons of 1821-2, “Life in London” was performed
with great éclat, at ten theatres in and around the metropolis, to
overflowing houses. But Pierce Egan at length became tired of the
successes of the playwrights in using his book, and resolved to try
his own hand at a dramatic version—or, as he termed it, “to take a
leaf or two out of his own book”—and the Author’s Piece was “got
up” and performed for the first time at Sadler’s Wells, under the
respectable management of Mr. Egerton, on Monday, April 8, 1822,
with most decided success.
It was thus announced by Mrs. Egerton, in the address written for
the occasion by T. Greenwood, Esq.
“To-night, my friends, this modern taste to meet,
We show you Jerry at his country seat;
Then up to town transport the rustic beau,
And show him ‘Life in London,’ HIGH and LOW.”

SADLER’S WELLS THEATRE.


Under the Direction of Mr. Egerton, of the Theatre Royal, Covent
Garden, Sole Proprietor.
The Brilliant Success, and increasing Attraction of Pierce Egan’s “Tom
and Jerry”: not exceeded by any performance ever yet produced;
and the celebrated Pony Races, exciting an interest equal to the Race
Course itself: being nightly performed to crowded Audiences, amidst
Roars of Laughter and Shouts of applause, will be repeated Every
Evening, at half-past six o’clock precisely:—
The new Pedestrian, Equestrian, and Operatic Extravaganza: in
Three Acts—of Gaiety, Frisk, Lark, and Patter, called

TOM AND JERRY.


Put into Shape, exclusively for this Theatre, by Pierce Egan.
Who trusts it will not be deemed unfair that he should take a Leaf or
Two out of his own Book, several other persons having made free
with the Work. The Piece now prepared for representation is not
entitled to the appellation of Tragedy, Comedy, Opera, Play, Farce,
Ballet, or Melodrama, yet partaking of the Qualities of all, and
possessing scenes High and Low in abundance, from the “Sky
Parlour” to the “Diamond Vault.” Out and Out, Rambles and Sprees,
East and West, and Lots of Characters, Up and Down. A variety of
Swells but no Dons: Corinthians and Costard-mongers of many Hues
and Colours: Flats and Sharps without a Note—Pinks and Tulips, but
no Flowers, yet always in the Hot Houses: and Hells without Devils,
only having Black Legs: Muslin and Hopsacks, according as the
creatures wear them: the whole forming a “Bit of Good Truth,” en
passant, in a Review of Life in London, developed by a precious Trio,
in the Persons of a Top-of-The-Tree-Hero Up and Dressed in all suits:
seconded by a slap-bang countryman, that neither hedge nor ditch
baulk his pursuits; and in unison with a prime piece of Logic without
Premises, yet always so much at Home, that Locke and Bacon were
muffs to him: also representing the Noble, Respectable, Mechanical,
and Tag Rag and Bob-tail part of Society, which constitute the
Corinthian Capital, and the Base of the Pillar.
The Overture, with the New and Selected Music, by Mr. Nicholson.
The Scenes from Drawings taken on the spot, by Mr. Greenwood,
assisted by Mr. Milldenhall and others. The Sporting Subjects, by Mr.
George Cruikshank, from designs by himself and Brother, Mr. I. R.
Cruikshank. The Quadrilles and Country Dances, by Mr. Kirby. The
Machinery, Platforms, and Race Course, by Mr. Copping. Dresses by
Mr. Townley and Mrs. Balding.

Corinthian Tom Mr. Elliott.


Jerry Hawthorn Mr. Keeley.
Bob Logic Mr. Vale.
Dusty Bob Mr. Walbourn.
African Sal Mr. Brady.
Little Jemmy Mr. Cooper.
Billy Waters Mr. Hartland.

To Start from the Winning Post on the Stage; Run three times Round
the Course.
Separate Matches, and afterwards for the Grand Sweepstakes.
PONY RACES.
Passing Into and Round the Pit.

Ponies. Colours.
1.—The Corinthian Pink.
2.—Bob Logic’s Miss Sly Stripe.
3.—Jerry’s Never to be beat Blue.
4.—Dusty Bob Black.
5.—Touch and-Go Blue and Pink.
6.—The Out-and-Outer Scarlet.
Stewards of the Race Logic, Tom, and Jerry.
Clerk of the Course Dusty Bob.

☞ The eagerness of several Ladies and Gentlemen to Promenade


the Course during the Race, having at times produced a
temporary delay and inconvenience, they are respectfully
intreated to observe the directions of the Clerk of the Course,
who will attend with Mrs. Dusty Bob (African Sal) in their
Carriage from Maiden Lane, Battle Bridge, for the purpose of
preserving order.

The Corinthian’s Diary.


A Celebrated Comic Song, written by
T. GREENWOOD, Esq.
And Sung by Mr. Vale, at Sadler’s Wells Theatre, in the Character of
Bob Logic.
SUNDAY, got floor’d, in groggy plight,
MONDAY, quite stale, took anti-bilious,
Pester’d by nausea, nerves not quite right,
And noisy duns quite supercilious:
A dish of Mocha, ’chovy toast,
Remov’d the spasms—increased attrition,
So started, when I’d skimm’d the Post,
To Tattersall’s, in high condition.

TUESDAY, got clean’d at Rouge et Noir,


And, done quite brown, was forc’d to toddle;
So then I vow’d to play no more,
Lest, like a lame duck, I should waddle.

WEDNESDAY, reflected; curs’d each star,


Swore never more a card to handle:
Went to the Fives Court, saw them spar,
And patronis’d Cribb, Neat, and Randall.

THURSDAY, bowl’d down to Ascot Heath,


To sport my blunt upon the races:
Rode my own mare almost to death,
For I had won three steeplechases:
Clean’d out again, I came away
Quite undismay’d, though out of feather,
At night I bolted to the play,
To drown ill-luck and care together.

Met with a spree, two glorious frays,


So went to work—I hate long parleys;
Kick’d up a row, then starr’d the glaze,
And mill’d, in style, a brace of Charley’s:
Morris’d away to Almack’s Rooms,
Danc’d a quadrille, alert and showy,
Call’d at the Finish, mops and brooms,
And tumbled to bed as drunk as Chloe.

FRIDAY, I went to see dear Nancy,


But found a Covey there before me,
Was forc’d to bolt, I’d lost my chance,
But Kate, I knew, would still adore me:
So off I set, stay’d SATURDAY,
My comforts took, then home departed;
Book’d for next week, with spirits gay,
I for a fresh game, on SUNDAY started.

SADLER’S WELLS.

PIERCE EGAN,
The Author
of

TOM & JERRY;


or,
Life in London.
Most respectfully informs the Public, and his numerous Friends in the
Sporting World, that:

(Before “all the Gold is taken off the Gingerbread,” being contented
with a Small Slice of it,) his

BENEFIT
is fixed for
Wednesday
The 25th September, 1822.
When a Variety Entertainment, will be performed, in which
THE AUTHOR
Will make his First and only Appearance on this Stage, in a
PRINCIPAL CHARACTER.

LIFE IN A SPREE.
A Spree’s the thing, with potent port made merry,
“Go it Bob Logic,” “Keep it up,” cries Jerry.

The Upper Story all abroad—Mr. Lushington at Work; and when the
Wine is in, the Wit is out—Ripe for any thing—How to make a Stop—
Watch go—And getting the best of the Timekeepers—Must make a
noise in the World:—
No way but this left to obtain renown,
Kick up a Row, and knock the Charlie’s down!

LIFE IN THE EAST.


All-Max ...... A bit of good Truth!
Tickets not necessary—Any Port in a Storm—Never a Jack without a
Jill—All happiness: no questions asked: and one half the world don’t
know how the other half lives—(or dies!)—No matter! Plenty of Taste
—Patter without ceremony—And not particular to a shade about
Lingo. Spoting a toe without a shoe, and no enquiry after the Snob’s
Bill—Reeling without steps—Flooring instead of Waltzing, and
nothing the matter. Country or colour no objection—Ladies in
mourning not prohibited—Black Sall don’t blush for her appearance
—And Dusty Bob not uneasy about his toggery—All the same One
Hundred Years hence!—Philosophy.
⁂ To prevent the trouble and fatigue of ascending the numerous
Steps to the Author’s Sky Parlour, (in Days of Yore, denominated a
Garret, as well as Tumbling over lots of Kids,) Tickets to be had of
Messrs. Sherwood, Neely, and Jones, Paternoster Row; Office of the
Weekly Dispatch, Wine Office Court, Fleet Street; at all the Sporting
Houses; and Places for the Boxes can be taken of Mr. Parker, at the
Box Offices, Sadler’s Wells, from 10 till 4.
Full Particulars will be duly Announced.
Boxes 4s. Pit 2s. Gallery 1s.
Glendinning, Printer, 25, Hatton Garden, London.

Brighton, of course, in common with all other large provincial towns


had its version of “Life in London.” The theatre was then under the
management of Mr. Samuel—or, as he was commonly known, Jerry
Sneak Russell, from the inimitable manner in which he personated
that character in Foote’s farce of “The Mayor of Garrat.” We have a
copy of the play-bill before us, and as we think the manager’s
remarks and the selection of criticisms are in their way curious, we
here append them, including the cast of characters:

THEATRE ROYAL, BRIGHTON.


LAST NIGHT BUT ONE.
TOM AND JERRY.
In announcing the successful piece of “Tom and Jerry” for this
evening, the manager feels great satisfaction in being able to quote
in its favour the following observations from the critiques in the
London and other newspapers. “The scenery, dresses, &c., are good
throughout, and much credit is due to the manager for the style in
which it is got up. It is with pleasure we remark that this piece has
been most judiciously freed from the impurities of dialogue, which
rendered it improper to meet the delicate ear of the gentler sex. We
therefore venture, without subjecting ourselves to reproach, to
recommend our readers to see ‘Life in London,’ to witness an
exposure of many impositions practised in real life, and be made ‘fly’
(the plain English of au fait) to the multum in parvo phrases which
are now introduced into passing conversations.”
“Brighton.—The theatre at this place has just produced its ‘Tom and
Jerry’ with great success, and, we may say, deservedly—every
objectionable point that might be thought to infringe on decorum
having been most ingeniously suppressed, without any diminution of
the whim and fire of its varied and entertaining scenes. This regard
to propriety argues much discretion, and seems to meet the
approbation of the beau monde resorting hither, for the theatre is
graced with abundance of fashion and beauty.”
“The ‘Tom and Jerry’ of the Brighton Theatre has good scenery, good
acting, and, what in such a piece is perhaps still better, good and
chaste dialogue to recommend it; it has been cleansed of its
impurities without injuring its life and spirit. As thus represented, it
cannot raise a blush on the cheek of the most fastidious female.”
On Wednesday Evening, September 12, 1822, will be reproduced the
highly popular and amusing Burletta of

TOM AND JERRY.


Corinthian Tom Mr. Power.
Bob Logic Mr. Chapman.
Jerry Hawthorn Mr. Russell.
Squire Hawthorn Mr. Chambers.
Tattersall Mr. Mortimer.
Yorkshire Cove Mr. Hatton.
Primefit Mr. Julian.
Bill Chaunt Mr. Whatford.
Dusty Bob Mr. Starmer.
Mr. Mace (Landlord of All Max in the East) Mr. Jenkins.
Billy Waters Mr. Sheen.
Mr. Muff Mr. Collier.
Gammoning Jack Mr. Mills.
Snoozy Mr. Cole.
Trifle Mr. Dale.
Little Jemmy Master Williams.
Chaffing Sam Mr. Wiber.
Tom Belcher Mr. Jones.
President of the Daffy Club Mr. Campbell.
Huntsmen, Watchmen, Villagers, Cadgers, &c., &c.
Corinthian Kate Miss M. Cooke.
Hon. Mrs. Gadabout Mrs. Clarke.
Patty Primrose Miss Carr.
Mary Miss Cramer.
Hon. Mrs. Trifle Miss Grosette.
Fortune Teller Mrs. Grosette.
Mrs. Allright Miss H. Grosette.
African Sal Miss Black.

Country Lasses, Ladies at Almack’s in the West, &c., &c.; Prospectus


of Scenery, &c., &c., as before.
To conclude with the Romantic Melo-drama of

VALENTINE AND ORSON.


Valentine Mr. Power.
Orson Mr. S. Chapman.

Creasy, Printer, Gazette Office, Brighton.


The notoriety which Tom and Jerry obtained in England, became the
topic of conversation amongst our Gallic neighbours—nay, it crept so
much into favour with the gay folks of Paris, Life in London was
speedily translated into French, under the title of “The Diorama; or,
Picturesque Rambles in London—containing the most faithful Notices
of the Character, Manners, and Customs of the English Nation, in the
various classes of Society. By M. S——.” The translation had a most
extensive circulation in France.
The reception of Tom and Jerry was equally flattering—
notwithstanding the great prejudices that had previously existed
against it—in Dublin. Mr. Wrench, from the Adelphi Theatre, was
specially engaged to play the part of Corinthian Tom. The first seven
nights produced £1300; and the house, on Mr. Wrench’s benefit
night, held £345.
The great success of “Life in London,” in its dramatic form in the
Irish capital lead up to the publication of:—
“Real Life in Ireland; or, the Day and Night Scenes,
Rovings, Rambles, and Sprees, Bulls, Blunders,
Bodderation, and Blarney of Brian Born, Esq., and his
elegant friend Sir Shawn O’Dogherty. 1829. Coloured
plates.”
In which the pictorial style of the Brothers Cruikshank was imitated
from an Hibernian point of view and colouring.
At both the Theatres in Edinburgh, Tom and Jerry attracted crowded
audiences, according to the Editor of the Edinburgh Dramatic
Review, who states thus:—
“At length the public of Edinburgh had opportunity of judging of the
merits of the above celebrated Extravaganza. From the general
tendency of the remarks which appeared in the newspapers, we
were led to suppose that this piece consisted of indecency and gross
vulgarity. From what we heard reported as to the numerous
indelicacies which this sketch of Fun, Frolic, Fashion, and Flash
contained, we were afraid that its success with our sober citizens
would have been precarious; but, we are happy to say, that the
applause which was bestowed on it by the unprecedentedly
numerous assemblage on Saturday evening, January 25, 1823,
which crowded the Caledonian Theatre, is a sufficient answer to the
chimerical doubts which were industriously circulated against its
propriety. There is nothing, as we before remarked, associated with
disgust or offence. There is neither one word, action, or situation, in
the whole course of the piece, that can possibly raise a blush, or
offend the most fastidious moralist!”
The Burletta of Tom and Jerry had been repeated so often all over
the kingdom, and particularly in the metropolis, that the performers,
notwithstanding the great applause they nightly received in the
above piece, absolutely became tired and worn-out with the
repetition of their characters, when the following piece of satire,
written by T. Greenwood, Esq., was published, entitled, “The Tears of
Pierce Egan, Esq., for the Death of ‘Life in London’; or, The Funeral
of Tom and Jerry. Dedicated to Robert and George Cruikshank, Esqs.
Price Two Shillings, with an engraving by George Cruikshank.”
“Beat out of the Pit, and thrown over the Ropes,
Tom and Jerry resign’d their last breath,
With them, too, expired the Manager’s hopes,
Who are left to deplore their sad death!

“Odd and various reports of the cause are about,


But the real one was this I opine:
They were run to a standstill, and, therefore, no doubt,
That the cause was a rapid decline.

“When death showed his Nob, out of Time they were beat,
And neither would come to the scratch;
They hung down their heads and gave up the last heat,
Not prepared with the Spectre to match.
“All wept at the Funeral! the Fancy and all—
Some new, but a great many mended:
And Egan, while Cruikshank and Bob held the pall,
As Chief Mourner in person attended!!!

“Their Sprees and their Rambles no more shall amuse,


Farewell to all nocturnal parleys:
The Town felt regret, as the bell tolled the news,
And no one rejoiced—but the Charleys!

“A monument, too, their kind Patrons will raise,


Inscribed on—‘Here lies TOM and JERRY,
Who, departing the Stage, to their immortal praise,
ONE THOUSAND NIGHTS made the Town merry!!!’

“May their souls rest in peace, since they’ve chosen to flit,


Like other great heroes departed;
May no mischief arise from their sudden exit,
Nor Pierce Egan die—broken-hearted!”
In reference to the above, Pierce Egan states that Jemmy Catnach,
the renowned Ballad-monger of the Seven Dials, in less than twelves
hours after the publication, produced a pirated edition for street
sale, for two-pence.
Mr. Pierce Egan, in his “Finish,” states that he reckoned no less than
sixty-five separate publications, which he enumerates in extenso, all
derived from his own work, and adds, with his usual amount of large
and small Capitals and italics—“We have been pirated, copied,
traduced; but, unfortunately, not enriched by our indefatigable
exertions; therefore notoriety must satisfy us, instead of the smiles of
FORTUNE. Our efforts have given rise to numerous productions in
the market of literature, yet we can assert, with a degree of
confidence hitherto unshaken, that none of our Imitators have dared
to think for themselves during the long period of seven years,
neither have they shown any originality upon the subject of ‘Life in
London’; but who have left it—disinterested souls!—to the Author and
Artist to put a CLIMAX to the adventures of Tom, Jerry, and Logic.”
The last remark is in reference to the publication of “Pierce Egan’s
Finish to the Adventures of Tom, Jerry, and Logic, in their Pursuits
through Life in and Out of London. With numerous coloured
illustrations by Robert Cruikshank. London: George Virtue & Co., Ivy
Lane, Paternoster Row.” Seven years after the date of “The Life in
London.” In common with almost all other sequels, or
“continuations” it was not successful—the fact being that Pierce
Egan, and the subject of his work were alike literally and financially
“used up!”
Old Jemmy Catnach, true to his line of life, soon joined what Pierce
Egan designates as the “Mob of Literary Pirates” who irritate the
poor author almost to madness, blast his prospects, impose on the
unwary by their imitations, and render his cash account all but
nugatory, and, just as he may be congratulating himself on the
success of his genius, receiving the smiles of Fame, and a trifling
sweetener from Threadneedle Street, as a reward for his exertions,
he may be attacked by Sappers and Miners—those pickers and
stealers who do not absolutely come under the denomination of
pickpockets, yet thieves to all intents and purposes, and, certainly,
robbers of the most unprincipled description—a set of vampires—
living upon “the brains” of other persons, and who dare not to think
for themselves.
Catnach brought out a broadside, or “whole-sheet,” for street-sale,
entitled:—
Larger Image

Text of Image

The “broadside,” which Pierce Egan calls—“Another wicked piracy, by


Catnach,” consists of twelve woodcuts,—of which we have given
facsimiles in our pages—it will be seen that they are reduced and
very roughly executed copies of the original plates by the Brothers
Cruikshank, but in reverse. Therefore the swaggering Notice to
Pirates which Jemmy Catnach published reads funny enough. The
letter-press matter consists of flash songs, and a poetical epitome of
the plot and design of the original work of “Life in London.” And
taking it as it stands, and from where it emanated, rather a
creditable performance, particularly when we take into consideration
—as duly announced by the street-patterer, that it was—“Just
printed and pub—lish—ed, all for the low charge of “Twopence.”
On the rarity of this Catnachian and piratical edition of “Life in
London” it is superfluous to enlarge, and it is easy to account for this
circumstance, if we reflect that the broadside form of publication is
by no means calculated for preservation; hundreds of similar pieces
printed at the “Catnach Press” and at other offices publishing for
street-sale must have perished. The more generally acceptable a
broadside or street-ballad became, and was handed about for
perusal, the more it was exposed to the danger of destruction. No
copy of Catnach’s version is preserved in the British Museum,
therefore, and for reason above stated, it must be considered as a
great “Literary Curiosity.”[38]

Old Stage Waggon.


As we have before observed, “Life in London” was dedicated by
permission to George IV., and it is a circumstance in itself which
looks singular enough in this Victorian age, that royalty should have
condescended to have had such a work dedicated to it. One
paragraph, which we are about to quote, strikes us as being a very
peculiar and free-and-easy style for an author to address himself to
a King of England. It is as follows:—
“Indeed, the whole chapter of ‘Life in London’ has been so
repeatedly perused by your Majesty in such a variety of shapes—
from the elegant A, the refined B, the polite C, the lively D, the
eloquent E, the honest F, the stately G, the peep-o’-day H, the
tasteful I, the manly J, the good K, the noble L, the stylish M, the
brave N, the liberal O, the proud P, the long-headed Q, the animated
R, the witty S, the flash T, the knowing U, the honourable V, the
consummate W, the funny X, the musical Y, and the poetical Z,—that
it would only be a waste of your Majesty’s valuable time to expatiate
further upon this subject.”
One notable effect of “Life in London,” particularly in its dramatised
form, must be recorded. It broke the heart of poor Billy Waters, the
one-legged musical negro, who died in St. Giles’s workhouse, on
Friday, March 21, 1823, whispering with his ebbing breath, a mild
anathema, which sounded very much like: “Cuss him, dam Tom—
meē—Tom—meē Jerry!”
Poor Billy endeavoured, up to the period of his last illness, to obtain
for a wife and two children what he termed, “An honest living by
scraping de cat-gut!” by which he originally collected considerable
sums of money at the West-end of the town, where his ribbon-
decked cocked hat and feathers, with the grin on his countenance,
and sudden turn and kick out of his wooden limb, and other antics
and efforts to please, excited much mirth and attention, and were
well rewarded from the pockets of John Bull. The burden of Billy’s
ditty “from morn to dewy eve,” and from January to December, was:

Polly will you marry me—Polly don’t you cry,
Polly will you marry me—Polly don’t you cry:—
Cry—cry—cry!

BILLY WATERS.
Mr. W. T. Moncrieff, the dramatist, is responsible for the following
biographical notice of this old London Street Character:—“Of this
meritorious and lamented individual, we had with great trouble
collected from various sources, an ample and interesting Biography.
But unfortunately for posterity, in the same classic regions where he
lost his life, we also lost his life; and, to tell the truth under the
influence of the same seductive fluid too—Daffy!—we can therefore
only present our reader with a few brief notices from memory.”
Billy Waters, was born in the powerful African kingdom of
Tongocongotaboo, where he was a native Prince, and bore the name
of Pokikokiquanko; from this place he was at an early age, to the
universal regret of his loving subjects, kidnapped, by ‘an auld
Quaker,’ who bought him from his treacherous attendants, for two
axes, a frying-pan and a bag of nails. This black piece of business
made him a slave, in the French settlement, at Demarara, from
whence however he speedly took French leave, and entered, we
believe, the British navy as a cook par excellence on board the
Ganymede sloop of war, under the command of Sir John Purvis,
where, during a fierce engagement, he lost a leg, some say gallantly
fighting the enemies of old England, though others insinuate it was
through falling down the cockpit ladder, in his great hurry to hide
himself. His own version was that he fell from the top-sail yard to the
quarter deck during a storm, we cannot pretend to decide which was
the fact, it however occasioned his being sent to England, as unfit
for service. Arriving in London, he betook himself to that wild mode
of life, which best suited his origin; the trammels of civilized society,
had no charm for him; he scorned the mechanical rules of man, and
picked up his living wherever he could find it. Born a Prince, and
bearing a native princeliness in his appearance it is not to be
wondered at that his associates should speedly elect him to the regal
dignity of their tribe.
In the year 1812 Billy was solemnly inauguared ex cathedra into the
sovereignty of mendicityship—King of the Beggars—at the cellar of
St. Patrick in St Giles’, a rank he supported with great satisfaction
and majesty, till the luckless period when a rival Billy (Bodkin), by
being placed at the head of the mendicity society, virtually became
King of the Beggars in his own right. This—as he conceived it, cruel
usurpation by Bodkin, pricked Billy just a leetle too hard. From that
moment he drooped as a blighted lily, and like another black hero he
exclaimed—‘Othello’s occupation’s gone.’ The fickle British public
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like