100% found this document useful (4 votes)
203 views

Download Full Implementing Cryptography Using Python Shannon Bray PDF All Chapters

Using

Uploaded by

gogovilakhn69
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 (4 votes)
203 views

Download Full Implementing Cryptography Using Python Shannon Bray PDF All Chapters

Using

Uploaded by

gogovilakhn69
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/ 66

Download Full Version ebookmass - Visit ebookmass.

com

Implementing Cryptography Using Python Shannon


Bray

https://ebookmass.com/product/implementing-cryptography-
using-python-shannon-bray/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmass.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Bayesian Optimization: Theory and Practice Using Python


1st Edition Peng Liu

https://ebookmass.com/product/bayesian-optimization-theory-and-
practice-using-python-1st-edition-peng-liu/

ebookmass.com

Python Programming: Using Problem Solving Approach 1st


Edition Reema Thareja

https://ebookmass.com/product/python-programming-using-problem-
solving-approach-1st-edition-reema-thareja/

ebookmass.com

Machine Learning on Geographical Data Using Python 1st


Edition Joos Korstanje

https://ebookmass.com/product/machine-learning-on-geographical-data-
using-python-1st-edition-joos-korstanje/

ebookmass.com

Davidson Medicine 24th Edition Ian D Penman

https://ebookmass.com/product/davidson-medicine-24th-edition-ian-d-
penman/

ebookmass.com
The Prepper’s Long Term Survival Bible | 11 Books in 1: A
Guide to Thriving Self-Sufficiently During Disaster
Scenarios Jim Grylls
https://ebookmass.com/product/the-preppers-long-term-survival-
bible-11-books-in-1-a-guide-to-thriving-self-sufficiently-during-
disaster-scenarios-jim-grylls/
ebookmass.com

Microplastic pollution in coastal ecosystem off Mumbai


coast, India Udai Ram Gurjar & K.A Martin Xavier & Satya
Prakash Shukla & Ashok Kumar Jaiswar & Geetanjali
Deshmukhe & Binaya Bhusan Nayak
https://ebookmass.com/product/microplastic-pollution-in-coastal-
ecosystem-off-mumbai-coast-india-udai-ram-gurjar-k-a-martin-xavier-
satya-prakash-shukla-ashok-kumar-jaiswar-geetanjali-deshmukhe-binaya-
bhusan-nayak/
ebookmass.com

Imagining Outer Space: European Astroculture in the


Twentieth Century 2nd Edition Alexander C.T. Geppert (Ed.)

https://ebookmass.com/product/imagining-outer-space-european-
astroculture-in-the-twentieth-century-2nd-edition-alexander-c-t-
geppert-ed/
ebookmass.com

Netter's Clinical Anatomy E-Book 4th ed Edition Hansen

https://ebookmass.com/product/netters-clinical-anatomy-e-book-4th-ed-
edition-hansen/

ebookmass.com

How to Date the Guy You Hate: An Enemies to Lovers Romance


(Eden Hills Book 2) Julie Kriss

https://ebookmass.com/product/how-to-date-the-guy-you-hate-an-enemies-
to-lovers-romance-eden-hills-book-2-julie-kriss/

ebookmass.com
Violets And Violence: MM Paranormal Mystery Romance (Tokyo
MPD Mysteries Book 3) M. Kato

https://ebookmass.com/product/violets-and-violence-mm-paranormal-
mystery-romance-tokyo-mpd-mysteries-book-3-m-kato/

ebookmass.com
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
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.
Chapter 1 ■ Introduction to Cryptography and Python 9

Testing Your Install


Once you have selected the platform of your choice, open the Python IDE. Find
the Python console panel and type the following:
>>> print('Hello World')
Hello World
>>> x = 100
>>> x*(1 + 0.5)**10
5766.50390625
>>> import math
>>> math.sqrt(49)
7.0

If everything goes as expected, you should see the output shown in Figure 1.3.

Figure 1.3: Python installed successfully

Diving into Python Basics


Prior to getting into the variables, spacing, strings, and loops, I will cover a few
of the basics you will need to know. Names in Python are case sensitive and
cannot start with a number. They can contain letters, numbers, and underscores.
Some examples include:
■■ alice
■■ Alice
■■ _alice
■■ _2_alice_
■■ alice_2

The language includes a number of reserved words, such as and, assert,


break, class, continue, def, del, elif, else, except, exec, finally, for, from,
global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while.
10 Chapter 1 ■ Introduction to Cryptography and Python

The goal of this book is not to teach Python from the ground up; it is, how-
ever, logical that you may be coming from another scripting or programming
language and may need a brief overview of the nuances of Python. While keep-
ing it as short as possible, in this section I discuss variables, operators, strings,
loops, and files. The hope is to give you enough information that you can debug
your Python code in the case of a typo.
One major difference between Python and many other languages is that
whitespace is meaningful, and many of your early errors probably will be a
result of indentation being misused. A newline in Python ends the line of code
unless you use the backslash (\) character. You will find that you need to use
consistent indentation throughout your code. The first line of code with less
indentation is outside a code block, whereas the lines with more indentation
start a nested block.
As with other languages, Python allows you to comment your code. Com-
menting your code should be considered a must. Some of the comments in the
code used in this book have been removed to shorten the code examples, but
you will be well-served by comments as you revisit previously written code.
In Python, comments start with #; everything following the pound sign will
be ignored.

Using Variables
The programs you write throughout this book will need to store values so
they can be used at a later time. Values are stored in variables; the use of a var-
iable is signified by the = sign, which is also known as the assignment operator.
For example, if you wanted to store the value 21 in a variable named age, enter
age = 21 into the shell:
>>> age = 21

Variables can be overwritten or used in calculations. Explore the following


by typing it into your shell:
>>> age + 9
30
>>> age
21
>>> age = age + 9
>>> age
30

Python doesn’t enforce any variable naming conventions, but you should use
names that reflect the type of data that is being stored. It is important to know
Chapter 1 ■ Introduction to Cryptography and Python 11

that in Python, variable names are case sensitive, so age and Age represent two
different variables. This overview shows the use of variables with numbers; we
will examine the use of variables and strings next.

Using Strings
Strings allow you to use text in programming languages. In cryptography, you
use strings a great deal to convert plaintext to ciphertext and back. These values
are stored in variables much like the numeric examples used in the preceding
section. Strings in Python are stored using the single quote (‘) or double quote
(“); it does not matter which quote you use as long as they are matching. To see
an example, type the following into the shell:
>>> name = 'John'
>>> name
'John'

The single quotes are not part of the string value. Python only evaluates the
data between the quotes. If you wanted to set a variable to an empty string, you
would use the following:
>>> name = ''

In Python, you can concatenate multiple strings together by using the plus
(+) operator. See the following example:
>>> first = 'John'
>>> last = 'Doe'
>>> name = first + last
>>> name
'JohnDoe'

Notice that the strings concatenate exactly the way they store values; if you
need a word separation, plan for the use of spaces.

Introducing Operators
You have now seen the + operator used in both numeric and string variables.
Other operators can be broken down into the following categories: arithmetic,
comparison, logical, assignment, bitwise, membership, and identity.

Understanding Arithmetic Operators


Arithmetic operators perform mathematical calculations (see Table 1.1).
12 Chapter 1 ■ Introduction to Cryptography and Python

Table 1.1: Arithmetic Operators

OPERATOR DESCRIPTION EXAMPLE


+ Addition 10 + 20 will give 30
- Subtraction 10 - 5 will give 5
* Multiplication 10 * 10 will give 100
/ Division 10 / 2 will give 5
% Modulus 20 % 10 will give 0
** Exponent 10**2 will give 100
// Floor Division 9//2 is equal to 4 and 9.0//2.0 is equal to
4.0

Most of these operators work precisely the way you expect from other
programming languages. It is critical to our exploration to examine modular
(%) arithmetic in detail as it plays an essential role in cryptography. We write
things like 28≡2(mod26), which is read out loud as “28 is equivalent to 2 mod
26.” While not entirely accurate, modular arithmetic focuses on the remainder.
In our example, 26 divides into 28 one time with two remaining, or x(mod p)
as the remainder when x divides into p. We can say that a≡b(mod q) when
a−b is a multiple of q. So 123≡13(mod 11) because 123−13=110=11⋅10. Now I’ve
heard folks describe the remainder of x mod p, which does refer to the unique
number between 0 and p−1, which is equivalent to x. An infinite sequence of
numbers are equivalent to 53(mod13), but out of that continuous sequence, there
is ­precisely one number that is positive and smaller than 13. In this case, it’s 1.
In a math setting , I would call 1 the canonical representative of the equivalence
class containing 53 modulo 13.
Table 1.2 shows some examples to help you wrap your head around the
concepts; they will be presented again when you examine ciphers and explore
finding the modular inverse in cryptographic math.

Table 1.2: Arithmetic Operator Examples

EXPRESSION DESCRIPTION SYNTAX


28 (mod 26) 28 is equivalent to 2 mod 26 28 % 26
29 (mod 26) 29 is equivalent to 3 mod 26 29 % 26
30 (mod 26) 30 is equivalent to 4 mod 26 30 % 26

One additional feature of Python is the use of the multiplication operator with
strings. The feature can be advantageous when you need to create specifically
Chapter 1 ■ Introduction to Cryptography and Python 13

formatted strings that may be used in some attacks such as buffer overflows.
One example can be examined using the print function, as shown here:
>>> # Python 2.7
>>> print 'a' * 25
aaaaaaaaaaaaaaaaaaaaaaaaa

>>> # Python 3.5


>>> print ('a' * 25)
aaaaaaaaaaaaaaaaaaaaaaaaa

N OT E Python 3 and higher require you to use Print() as a function. You must
include the parentheses.

Understanding Comparison Operators


The comparison operators, also known as relational operators, compare the oper-
ands (values) on either side and return true or false based on the condition (see
Table 1.3).

Table 1.3: Comparison Operators

OPERATOR DESCRIPTION EXAMPLE


== Compares two operands to see if they are equal; (10 == 20) is not
if the values are equal, it returns true. true
!= Compares two operands to see if they are not (10 != 20) is true
equal; if the values are not equal, it returns true.
<> Compares two operands to see if they are not (10 <> 20) is true
equal; if the values are not equal, it returns true.
> If the operand on the left is greater than the (10 > 5) is true
operand on the right, the operation returns true.
< If the operand on the right is greater than the (10 < 20) is true
operand on the left, the operation returns true.
>= If the operand on the right is equal to or less than (10 >= 5) is true
the value on the left, the condition returns true.
<= If the operand on the left is equal to or less than (5 <= 10) is true
the value on the right, the condition returns
true.

Understanding Logical Operators


The logical operators include and, or, and not (see Table 1.4).
14 Chapter 1 ■ Introduction to Cryptography and Python

Table 1.4: Logical Operators

OPERATOR DESCRIPTION EXAMPLE


and (logical AND) If both the operands evaluate to (a and b) is true.
true, then condition becomes true.
or (logical OR) If any of the two operands are non- (a or b) is true.
zero, then condition becomes true.
not (logical NOT) Used to reverse the logical state of Not(a and b) is false.
its operand.

Understanding Assignment Operators


You first explored the assignment operators when we covered variables. In
addition to using the equal sign, Python offers many assignments that work
as a shorthand for more extended tasks. To get an understanding of how this
works, examine Table 1.5.

Table 1.5: Assignment Operators

OPERATOR DESCRIPTION EXAMPLE


= Assigns values from right-side operands to c = a + b assigns
left-side operands. value of a + b into c
+= (add AND) Adds the right operand to the left operand c += a is equivalent
and assigns the result to the left operand. to c = c + a
-= (subtract Subtracts the right operand from the left c -= a is equivalent
AND) operand and assigns the result to the left to c = c - a
operand.
*= (multiply Multiplies the right operand with the left c *= a is equivalent
AND) operand and assigns the result to the left to c = c * a
operand.
/= (divide Divides the left operand with the right c /= a is equivalent
AND) operand and assigns the result to the left to c = c /
operand.
%= (modulus Takes modulus using two operands and c %= a is equivalent
AND) assigns the result to the left operand. to c = c % a
**= Performs exponential (power) calculation on c **= a is equivalent
(exponent operators and assigns the value to the left to c = c ** a
AND) operand.
//= (floor Performs floor division on operators and c //= a is equivalent
division) assigns the value to the left operand. to c = c // a
Chapter 1 ■ Introduction to Cryptography and Python 15

Understanding Bitwise Operators


The bitwise operators work on bits and perform bit-by-bit operations (see Table 1.6).
Assuming a = 60 and b = 13, the binary format of a and b will be as follows:
a = 0011 1100
b = 0000 1101

Table 1.6: Bitwise Operators

OPERATOR DESCRIPTION EXAMPLE


& (binary AND) Copies a bit to the result if it exists in (a & b) (means 0000
both operands. 1100)
| (binary OR) Copies a bit if it exists in either (a | b) = 61 (means
operand. 0011 1101)
^ (binary XOR) Copies the bit if it is set in one operand (a ^ b) = 49 (means
but not both. 0011 0001)
~ (binary One This operator is unary and has the (~a ) =-61 (means 1100
Complement) effect of “flipping” bits. 0011 in two’s
complement form due to
a signed binary number.
<< (binary Left The left operand’s value is moved left a << 2 = 240 (means
Shift) by the number of bits specified by the 1111 0000)
right operand.
>> (binary Right The left operand’s value is moved a >> 2 = 15 (means
Shift) right by the number of bits specified 0000 1111)
by the right operand.

Understanding Membership Operators


Membership operators test for membership in a sequence, such as strings, lists,
or tuples. There are two membership operators, in and not in, as shown in
Table 1.7.

Table 1.7: Membership Operators

OPERATOR DESCRIPTION EXAMPLE


in Evaluates to true if it finds a variable in x in y; here in results in a
the specified sequence and false 1 if x is a member of
otherwise. sequence y.
not in Evaluates to true if it does not find a x not in y; here not in
variable in the specified sequence and results in a 1 if x is not a
false otherwise. member of sequence y.
16 Chapter 1 ■ Introduction to Cryptography and Python

Understanding Identity Operators


Identity operators compare the memory locations of two objects. There are two
identity operators, is and is not, as shown in Table 1.8.

Table 1.8: Identity Operators

OPERATOR DESCRIPTION EXAMPLE


is Evaluates to true if the variables on either x is y; here is results in
side of the operator point to the same 1 if id(x) equals id(y).
object and false otherwise.
is not Evaluates to false if the variables on either x is not y; here is not
side of the operator point to the same results in 1 if id(x) is not
object and true otherwise. equal to id(y).

Using Conditionals
You will need to evaluate various conditions as you are writing your code;
conditional statements in Python perform different actions or computations and
decide whether a condition evaluates to true or false. We use the IF statement
for our Boolean test. The syntax is as follows:
If expression
Statement
Else
Statement

To use it in an actual program, type the following:


>>> # Python 3.5
>>> for i in range(1,5):
>>> if i == 2:
>>> print ('I found two')
>>> print (i)

In addition to the IF statement, Python also makes use of ELSE and ELIF. ELSE
will capture the execution if the condition is false. ELIF stands for else if; this
gives us a way to chain several conditions together. Examine the following:
>>> # Python 3.5
>>> for i in range(1,5):
>>> if i == 1:
>>> print ('I found one')
>>> elif i == 2:
>>> print ('I found two')
>>> elif i == 3:
Chapter 1 ■ Introduction to Cryptography and Python 17

>>> Print ('I found three')


>>> else
>>> Print ('I found a number higher than three')
>>> print (i)

Using Loops
When you use scripting or programming languages, you can perform a set of
statements in multiple repetitions. Loops give us the ability to run logic until a
specific condition is met. For the sake of what you use in this book, this section
shows the for loop, the while loop, the continue statement, the break statement,
and the else statement. Unlike other programming languages that signify the end
of the loop by using keywords or brackets, Python uses line indentations. You
need to focus on how your syntax is spaced when writing and testing your code.

for
The for loop is used to iterate over a set of statements that need to be repeated
n number of times. The for statement can be used to execute as a counter in a
range of numbers. The following syntax prints out the values 1, 2, 3, 4, 5, 6, 7, 8, 9:
>>> # Python 3.5
>>> for i in range(1, 10):
>>> print (i)

The for loop can also execute against the number of elements in an array.
Examine the following snippet, which produces the result 76:
>>> # Python 3.5
>>> numbers = [1, 5, 10, 15, 20, 25]
>>> total = 0
>>> for number in numbers:
>>> total = total + number
>>> print (total)

As with numbers, the same technique is useful against string arrays. The
following outputs three names—Eden, Hayden, and Kenna:
>>> # Python 3.5
>>> all_kids = ["Eden&", "Hayden&", "Kenna&"]
>>> for kid in all_kids:
>>> print kid
Eden
Hayden
Kenna
18 Chapter 1 ■ Introduction to Cryptography and Python

while
The while loop is used to execute a block of statements while a condition is true.
As with the for loop, the block of statements may be one or more lines. The
indentation of the following lines defines the block. Once a condition becomes
false, the execution exits the loop and continues. Before printing the final state-
ment, the following snippet prints 0, 1, 2, 3, 4:
>>> # Python 3.5
>>> count = 0
>>> while (count < 5):
>>> print count
>>> count = count + 1
>>> print ("The loop has finished.")

continue
The continue statement is used to tell Python to skip the remaining statements
in the current loop block and continue to the next iteration. The following snip-
pet will produce an output of 1, 3, 4. The continue statement skips printing
when i equals 2:
>>> # Python 3.5
>>> for i in range(1,5):
>>> if i == 2:
>>> continue
>>> print (i)

break
The break statement exits out from a loop. The following snippet produces an
output of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11. Once i = 12, the loop is abandoned:
>>> # Python 3.5
>>> for i in range(1,15):
>>> if i == 12:
>>> break
>>> print (i)

else
You can use the else statement in conjunction with the for and while loops to
catch conditions that fail either of the loops. Notice that since the count variable
equals 10 in the following example, the while loop does not execute. You should
only see the two final print messages:
>>> # Python 3.5
>>> count = 10
Discovering Diverse Content Through
Random Scribd Documents
Springf’d Republican p11a Je 6 ’20 160w

[2]
LAMBUTH, WALTER RUSSELL. Medical
missions: the twofold task. il $1 S. V. M. 266

20–9358

“The growth of medical work in Christian missions is a romantic


chapter in the record of the extension of the kingdom of God on
earth. The writer draws from a wide range of material and experience
and presents the great work of medical missions in a most attractive
form. The book furnishes a mighty appeal to the young man or
woman who is looking forward to the practice of medicine and
surgery as a life-work. One is forced to face the need of the world and
to decide whether it is right to remain in one’s own land struggling
for a practice, or whether it is far better to go where the need is
desperate and invest life there.”—Bib World

“The pictures are well chosen; the specific examples of effective


missionary service are stimulating; the field of study is wide and is
surveyed with discrimination. An excellent book for private reading
or class study.”

+ Bib World 54:650 N ’20 160w

“Unfortunately the book is propaganda and the references to the


adventures of the medical missionary are drowned in a
misrepresentation of heathendom. Although he, Bishop Lambuth,
does voice the cry for service in an antiquated religious idiom, he is
really bigger than his creed and values humanity more than
proselyting.”

− + N Y Evening Post p26 O 23 ’20 280w

LAMOTTE, ELLEN N. Opium monopoly. *$1


Macmillan 178.8

20–2983

“‘The opium monopoly,’ by Ellen N. LaMotte, the author of ‘The


backwash of war,’ ‘Peking dust,’ ‘Civilization,’ etc., is a remarkable
monograph on the ‘opium question,’ based upon government blue
book reports, statistical extracts and official data. In this work, the
author discusses the problems of opium monopoly and consumption
in India, the Malaya peninsula, Siam, Hongkong, Srawak, Turkey,
Persia, Mauretius, British Borneo and British Guiana, and gives a
brief outline of the history of the opium trade in China and of Great
Britain’s opium monopoly.”—N Y Call

“National pharisaism and a strong anti-English feeling are a


conspicuous part of the writer’s equipment, but the facts which she
adduces must give us to think.”

+ − Ath p685 My 21 ’20 80w

“Well documented.”

+ Booklist 16:258 My ’20


“One of the best arguments yet advanced against the mandatory
system pieced together at Paris.”

+ Dial 68:669 My ’20 50w

Reviewed by C: R. Hargrove

+ Freeman 2:501 F 2 ’21 840w

“Miss LaMotte, in spite of her rather obvious desire to have her


fling at Britain, is at the same time evidently actuated by a desire to
reveal a grievous state of affairs. Having exposed the outstanding
features of the cultivation and sale of opium by the British, it is
obviously Miss LaMotte’s duty to continue her interesting
investigations in this country.”

+ Lit D p89 My 1 ’20 900w

“Miss LaMotte’s little book might be taken more seriously if she


were not at such pains to paint Great Britain black. It is idle to draw
fine moral distinctions between the British government which sells
opium to the Japanese and the Japanese who smuggle it into China.
The whole trade is bad enough in all conscience, however, and to
have attacked it is to have done something useful.”

+ − Nation 110:805 Je 12 ’20 340w

“Miss LaMotte did a great service to the cause of human justice


when she wrote her admirable work. It will prove a valuable asset in
rousing the conscience of the civilized people of the world against
this gigantic international crime of drugging nations. Let us hope
that the book will soon be translated into various languages of the
civilized nations and the truth spread broadcast to remedy the
wrongs of the helpless millions.” Taraknath Das

+ N Y Call p10 Ap 25 ’20 2750w

“Miss LaMotte’s book is intended as a severe indictment of Great


Britain’s policy with regard to opium. Her account would, however,
be a fairer one if consideration were given to the British side of the
case as presented, for example, by Sir John Strachey in his ‘India: its
administration and progress.’”

+ − Review 2:400 Ap 17 ’20 280w


R of Rs 62:448 O ’20 60w

“It is a delight to read one of Miss LaMotte’s books, and even in


this which is little more than a pamphlet, one finds the unflinching
courage and the keen insight which made her ‘Peking dust’ and the
stories which make up ‘Civilization’ so different from the productions
of most tourists in the Far East.” E. W. Hughan

+ Socialist R 8:315 Ap ’20 400w

“No one who has in the last ten years studied the hydra-headed
problems of narcotism could be anything but grateful to Ellen
LaMotte for her book.... Does the American public realize to what
extent opium is coming in over the Canadian boundary? It might for
that reason alone pay that American public to open its eyes a little
wider to the facts of British opium sold at public monthly sales in
Calcutta as recorded in Ellen LaMotte’s ‘Opium monopoly.’”
Jeannette Marks
+ Springf’d Republican p11a Ap 11 ’20
2200w

“For two reasons the opium monopoly is worthy of our attention:


first, the world interest, the salvation of the eastern peoples, the
Chinese especially; second, the danger that the United States will
take China’s place as the great market for these products. Either is
enough to interest Survey readers in this small book, the author of
which has the gift of making official reports and statistics tell an
interesting and fascinating story.” J. P. Chamberlain

+ Survey 44:252 My 15 ’20 550w

LAMPREY, LOUISE. Masters of the guild. il


*$2.25 (3½c) Stokes

20–18171

Like the stories in the author’s previous book “In the days of the
guild” these new tales do honor to the ideals of fine craftsmanship of
the middle ages. The titles are: Peirol of the pigeons; A tournament
in the clouds; The puppet players; Padraig of the scriptorium; The
tapestry chamber; The fairies’ well; The wolves of Ossory; The road
of the wild swan; The sword of Damascus; Fool’s gold; Archiater’s
daughter; Cold Harbor; The wisdom of the galleys; Solomon’s seal;
Black magic in the temple; The end of a pilgrimage. Poems alternate
with the stories. There are illustrations by Florence Choate and
Elizabeth Curtis, and notes on the stories come at the end.
+ Booklist 17:123 D ’20

LANDOR, WALTER SAVAGE. Day-book of


Walter Savage Landor, chosen by John Bailey. *$1.25
Oxford 828

(Eng ed 20–16302)

“Men of taste, men with an ear for the classic note in prose, must
always read Landor. That some have failed in this elementary duty is
the burden of a delightful essay by Mr John Bailey prefixed to a little
collection of Landor’s prose and verse,—a fine quotation for every
day in the year, beginning with the famous epitaph on himself, and
proceeding with symphonic development to the Latin epitaph on a
young scholar. Mr Bailey—himself, as we know from other
publications, an agreeable compound of the man of letters and the
man of affairs—offers his little book, not as the last word in Landor,
but as the first—as the preliminary encouragement to that larger
reading it should do much to stimulate.”—Sat R

+ Ath p1037 O 17 ’19 400w


+ Boston Transcript p11 Ja 31 ’20 550w

“We recommend a course of Landor. In days when the rabble has


to be wooed with flattery, it is bracing to the spirit to find one, who,
liberal as he called himself, inhabited the mountain tops of life, and,
never descending among the wrangling crowds, beckons us
continually aloft.”

+ Sat R 128:507 N 29 ’19 1850w

“Charming little book.”

+ Spec 123:511 O 18 ’19 140w

“To glance through an admirable volume of selections from


Landor, such as that edited by John Bailey is to be filled with delight
and regret. What writer of the second rank has more to yield to the
discoverer than he? What prose more squarely can support the
weight of the exactest scrutiny than his?”

+ Springf’d Republican p8 N 8 ’19 280w


(Reprinted from Ath)
+ Springf’d Republican p13 F 1 ’20 1000w
(Reprinted from The Times [London] Lit
Sup p564 O 16 ’19)

“As, however, Mr Bailey implies by making a day-book of his


selections, Landor not only constantly said beautiful things
beautifully, but as constantly things that stand the wear and tear of
daily life. No doubt the blank page at the end of this charming little
book is provided to hold a good resolution—namely, whatever else
may happen in nineteen twenty-one, to read Landor through.”

+ The Times [London] Lit Sup p564 O 16


’19 850w
LANE, MRS ANNE (WINTERMUTE), and
BEALE, MRS HARRIET STANWOOD
[2]
(BLAINE). Life in the circles. (Deeper issues ser.)
*$1.25 Dodd 134

20–19176

This book is a continuation of the volume entitled “To walk with


God,” and contains “further lessons received through automatic
writing.” (Sub-title) There are lessons on will, knowledge, joy, truth,
understanding, sympathy, and love.

“The level of intelligence of the sending spirits is not very high—a


grade or two above the kindergarten.”

− N Y Evening Post p12 O 30 ’20 80w

LANE, MRS ANNE (WINTERMUTE), and


BEALE, MRS HARRIET STANWOOD
[2]
(BLAINE). To walk with God. (Deeper issues ser.)
*$1.25 Dodd 134

20–6367

A series of “lessons” which the authors received in the form of


automatic writings. An introduction gives the circumstances under
which the messages were received and the lessons have to do with
the power of love, helpfulness, kindness and the need for spiritual
guidance. The authors say: “We realise that it will be said that there
is nothing new in the teaching, and we admit that there is repetition
to what seems an unnecessary degree, but we pledge our word that
we have put nothing of our own into the text.” (Introd.)

“The fact that the wife of the Secretary of the interior and the
daughter of James G. Blaine are the recipients of these messages will
make a certain demand for the book.”

+ Booklist 16:327 Jl ’20

LANE, MRS ROSE (WILDER). Making of


Herbert Hoover. *$3.50 (4½c) Century

20–18582

Herbert Hoover represents America, says the author, and his is the
spirit of five generations of American pioneers. His life began at the
end of one pioneer age and the beginning of the other. His ancestors
had been sturdy pioneers of Quaker stock—his father a blacksmith.
They had conquered the soil, he conquered the world of finance.
Much of the material of the book has been collected by Charles
Kellogg Field, classmate and friend of Hoover.

“Written with the interest in really delightful settings and small


circumstances of life such as a novelist employs to characterize a
hero. Children will like this book.”
+ Booklist 17:113 D ’20

“It is a story of a wonderful career, written with a brightness and a


dash that captivates and enthralls.”

+ Boston Transcript p7 O 30 ’20 580w


+ N Y Evening Post p9 O 30 ’20 240w
R of Rs 62:669 D ’20 100w

“The book is readable for its vivid presentation of an active and


adventurous career.”

+ Springf’d Republican p5a Ja 30 ’21


330w

LANG, EDITH, and WEST, GEORGE. Musical


accompaniment of moving pictures. il pa *$1.25
Boston music co.; Schirmer 780

20–4471

“A practical manual for pianists and organists and an exposition of


the principles underlying the musical interpretation of moving
pictures.” (Sub-title) There are three parts: Equipment; Musical
interpretation; The theatrical organ. Musical scores are given and
there is an index.
“Not exhaustive but very suggestive to the player and illuminating
to the listener.”

+ Booklist 16:232 Ap ’20

“It is a book we can warmly commend.”

+ Survey 44:309 My 29 ’20 260w

LANGDON-DAVIES, JOHN. Militarism in


education; a contribution to educational
reconstruction. 80c Headley bros., London; for sale
by Survey 371.43

19–12681

“The author contrasts the German and English systems of


education, gives an account of the scholastic methods adopted in
Norway, deals at considerable length with the aims of real physical
training, devotes a chapter to boy scouts, and brings many
arguments against compulsory national service, to which he is
strongly opposed.”—Ath

Ath p475 Je 13 ’19 50w

“The faults of anti-militarist literature are usually rancour,


sentimentality, and exaggeration. Mr Langdon-Davies has escaped
all three. The merit of this book consists in its clearness and its
shortness, in the fact that the author knows what he wants to prove,
and proceeds to prove it without fuss or sentiment and with
considerable moderation.”

+ Ath p621 Jl 18 ’19 550w


Brooklyn 12:62 Ja ’20 30w

“From the point of view of physical health, Mr Langdon-Davies


gives many proofs from experienced educationists of the deleterious
effects on children of military training. In a valuable chapter on the
psychological aims of physical education, he points out that character
must be built on the basis of instinct and that ‘the cornerstone of the
superstructure is the acquirement of habit and self-control.’” B. U.
Burke

+ Nation 110:335 Mr 13 ’20 1150w

[2]
LANGFELD, HERBERT SIDNEY. Aesthetic
attitude. *$3.50 Harcourt 701

21–113

The author holds that a sense of beauty is as vital to the complete


existence of the individual and of the race as is the sense of justice
and that a nascent appreciation of what is beautiful can be developed
into a strong, useful and satisfying reaction to the world of colors,
sounds and shapes. The emphasis of the book, therefore, is put upon
a description of the nature of appreciation and of the mental
processes involved therein, ... its wider applications to the problems
of human happiness. He concludes that “whenever we are able to
adjust ourselves successfully to a situation, so that our responses are
unified into a well-integrated or organized form of action, we call
that situation beautiful, and the accompanying feeling one of
æsthetic pleasure.” The contents are: Introduction; The science of
beauty and ugliness; The æsthetic attitude (two chapters); Empathy;
Illustrations of empathy from the fine arts; Unity and imagination;
Illustrations of unity from the fine arts; Balance and proportion;
Illustrations of balance from the fine arts; The art impulse;
Conclusion; Index.

LANGFORD, GEORGE. Pic, the weapon-maker.


il *$1.75 Boni & Liveright

20–13544

“Like Kipling’s ‘Jungle stories,’ but laid in western Europe perhaps


40,000 years ago, the story of ‘Pic, the weapon-maker,’ is George
Langford’s popularization as fiction of such facts as science has
revealed about the cave men of the Mousterian era. Pic, the ape-boy,
with the hairy mammoth and the wobbly rhinoceros, formed a triple
alliance of friendship and adventure. Pic was in search of the secret
of cutting flints in such a way as to put a fine edge on them without
spoiling them in the attempt, and before the story closes he has
found it and made it the key to renewed fellowship with the tribe that
had cast him out. As to the scientific quality of the story no less an
authority than Henry Fairfield Osborn, director of the American
museum of natural history, writes a brief approving introductory
note.”—Springf’d Republican

+ Booklist 17:37 O ’20


“Anthropology and adventure are jumbled—naively, at times—in
this story which, for all its prehistoric licence, still clings to the
technique of Stratemeyer and other weavers of juvenile romance.” L.
B.

− + Freeman 1:526 Ag 11 ’20 280w

“A troublesome fault is the author’s imaginative cocksureness. A


higher degree of vagueness would actually have yielded an
impression of greater exactness here. But where all is dark and
chaotic, much must be forgiven to the first imaginative explorers. It
is certain that Mr Langford’s book will fruitfully awaken the interest
of the young in the remote past of the race, nor will maturer minds
read it without some fresh light on dim places.” Ludwig Lewisohn

+ − Nation 111:190 Ag 14 ’20 260w

“The characterization of the Mammoth and the Rhinoceros is not


the least clever part of this whimsical, fanciful and yet true story of
this little, prehistoric man, and it is with real regret that the book is
laid aside as the story closes.”

+ N Y Times p18 S 19 ’20 650w

“An unusual and a powerful juvenile. The spirit and narrative of


the book will be enjoyed even by children too young to attempt the
reading for themselves.” R. D. Moore

+ Pub W 97:1296 Ap 17 ’20 180w


Springf’d Republican p11a Ag 22 ’20
300w
Wis Lib Bul 16:198 N ’20 60w

LANIER, HENRY WYSHAM. Book of bravery;


third series. il *$2.50 Scribner 920

20–15939

“This is a book of courage, wherein people in their daily pursuits


meet with obstacles which they surmount through excellences of
character. The man who is paid for his brave work, like the life-saver,
the policeman, the fireman, is none the less brave and his deed is
none the less fraught with the tingling quality of bravery. In the
missionary field and on the battlefield Mr Lanier finds material for
this volume.”—Lit D

Booklist 17:123 D ’20

“It is a collection worth making.”

+ Ind 104:378 D 11 ’20 60w


+ Lit D p96 D 4 ’20 90w

“For the inspiration of these volumes, children and parents alike


may well be grateful to Mr Lanier.” M. H. B. Mussey

+ Nation 111:sup674 D 8 ’20 60w


“The stories are vividly presented, and the book is one to stir the
heart of youth.” Hildegarde Hawthorne

+ N Y Times p9 D 12 ’20 80w


+ Outlook 126:470 N 10 ’20 50w

LANKESTER, SIR EDWIN RAY. Secrets of


earth and sea. il *$3.50 Macmillan 504

“These popularly written chapters on a wide variety of scientific


and anthropological topics, such as What is meant by a species?
Species in the making; The biggest beast; The earliest picture in the
world; The art of pre-historic men; The swastika; etc., form a sequel
to the same author’s ‘Science from an easy chair’ and ‘Diversions of a
naturalist,’ and like them is mainly a reprint, with considerable
additions, of articles published in daily or weekly papers.”—The
Times [London] Lit Sup S 23 ’20

Booklist 17:144 Ja ’21

“The essays are entertaining but have no high literary qualities.


Men like Shaler, Burroughs, Muir, Mills, and Slosson have done this
sort of book far better in America.”

− + N Y Evening Post p12 N 27 ’29 140w


+ N Y Times p6 Ja 2 ’21 3100w
“Let it be said at once that ‘Secrets of earth and sea,’ though
extremely interesting, is not in the best sense as diverting as was
‘Science from an easy-chair.’ The subjects treated are delightfully
interesting to the layman but the style is unfortunately rather
redundant and heavy.”

+ − Spec 125:861 D 25 ’20 190w

“The book is indicative of what will be common in that happy day


when science will be written about as fully and as charmingly as
purely literary subjects are today.”

+ Springf’d Republican p8 D 3 ’20 350w


The Times [London] Lit Sup p623 S 23
’20 90w

“Parents and guardians who are desirous of introducing their boys


to the study of natural science and who, in pursuance of that
praiseworthy aim, are looking for a book which, while sound and
exact in statement, is yet light and easy to read and, above all, has no
tincture of the school classroom, would do well to think of Sir Ray
Lankester’s ‘Secrets of earth and sea.’”

+ The Times [London] Lit Sup p831 D 9


’20 370w

LANSBURY, GEORGE. These things shall be. $1


(5½c) Huebsch 261
In these six essays the author proclaims himself a revolutionist and
downright hater of the existing order but he does not see salvation in
a terrific cataclysm with hopes of a new order arising from the ruins
of the old. He pins his faith upon a change of heart in individual men
and women and in the message “Ye must be born again.” The spirit
of the essays is faith in a God of love and in the teachings of Christ of
human brotherhood and love and cooperation. Mr Lansbury is editor
of the London Daily Herald.

Ath p166 Ja 30 ’20 80w

“He has nothing startlingly new to say, but the serenity and
steadfastness of his faith in humanity and in a society of individuals
living the gospel of Christian love, will afford comfort and
reassurance to minds tired for the moment of their searching.”

+ Booklist 17:142 Ja ’21


+ Survey 44:355 Je 5 ’20 310w

LANSBURY, GEORGE. What I saw in Russia.


*$1.50 (3c) Boni & Liveright 914.7

21–434

In his introduction to the American edition of this book, Matthew


F. Boyd, after reviewing the attitude towards Russia of the European
powers, of which France is now the only one still openly hostile, finds
that the United States has once more become the arbiter of world
destiny and that her policy towards Russia will decide the future of
the world. George Lansbury went to Russia to discover what was the
spirit moving the men and women responsible for the revolution. He
found it to be that of a band of people striving to build the New
Jerusalem, that they are actuated by purely moral and religious
motives and are doing what Christians would call the Lord’s work.
Contents: Finland to Moscow; Lenin and other leaders; Lenin,
bolshevism and religion; Co-operation, trade and business; Trade
unions and labour organization; Children and education; Law and
order; Prisoners and captives; About people; Public health; Moscow
to London; Appendix.

“The chapter on religion will interest churchmen.”

+ Booklist 17:142 Ja ’21

“Any one who wishes to gain a vivid picture of life in Soviet Russia,
drawn with entire honesty and animated by sympathy and good will
should, by all means, read Mr Lansbury’s book.” A. C. Freeman

+ N Y Call p10 D 19 ’20 420w

LANSING, MARION FLORENCE, and


GULICK, LUTHER HALSEY. Food and life. il 68c
Ginn 613.2

20–5746

The book has been suggested by the new importance that the war
has placed on food as a universal human need and on the desirability
of a full knowledge of its potentialities even for children. “From its
pages the child will learn the facts he should know concerning the
great food business into which he is born and in which he is a
partner.... There is hardly a virtue or an ideal of family, community,
and world life which does not take a natural place in a study of the
fundamental human problem of food.” (Preface) Every aspect of the
food problem, the personal, the social, the economic and the
scientific is entertainingly put before the child in detached stories.
The contents are: A life business; The food tether; In business for
yourself; Food as fuel; Our dally bread; The magic touch; Likes and
dislikes; A world appetite; The first step; The moment of eating; In
the world’s food market; The pitcher and the loaf; The gift of a
garden; Kitchen service; Food and money; For future use; Food and
health; Food and the government; At a world table. In Facts and
figures are given tables, charts and lists of a scientific nature. The
book has an index and illustrations.

+ Booklist 17:123 D ’20

LASKI, HAROLD JOSEPH. Political thought in


England from Locke to Bentham. (Home univ. lib.)
*75c (1c) Holt 320.9

20–14002

The author holds that the eighteenth century began with the
revolution of 1688, that it was a period of quiet after a storm and can
make little pretence to discovery, but that its stagnation was mainly
on the surface and that the period was fruitful of much thought
resulting in future activity. The significance of Locke—who alone in
this period confronted the general problems of the modern state—of
Burke, Hume, Adam Smith and their contemporaries, forms the
subject matter of the book. Contents: Introduction; The principles of
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!

ebookmass.com

You might also like