Skip to Main Content
Hands-On Cryptography with Python
book

Hands-On Cryptography with Python

by Samuel Bowne
June 2018
Beginner to intermediate content levelBeginner to intermediate
100 pages
2h 9m
English
Packt Publishing
Content preview from Hands-On Cryptography with Python

Implementing the Caesar cipher in Python

Let's go ahead and open the Terminal and follow these steps to implement Caesar cipher in Python:

  1. We will use Python in interactive mode first and then make a string that just has some letters in order to test this method:
>>> str = "ABCDE">>> str.find("A")0>>> str.find("B")1>>> exit()
  1. Because we understand how the string methods work, we'll exit and go into the nano text editor to look at the first version of our script:
$ nano caesar1.py
  1. When you run the command, you will get the following code:
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"str_in = raw_input("Enter message, like HELLO: ")n = len(str_in)str_out = ""for i in range(n):   c = str_in[i]   loc = alpha.find(c)   print i, c, loc,  newloc = loc + ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Cryptography in Python: Learning Correct Cryptography by Example

Practical Cryptography in Python: Learning Correct Cryptography by Example

Seth James Nielson, Christopher K. Monson
Cryptography Algorithms

Cryptography Algorithms

Massimo Bertaccini

Publisher Resources

ISBN: 9781789534443Supplemental Content