Book Image

Mastering Python Scientific Computing

Book Image

Mastering Python Scientific Computing

Overview of this book

Table of Contents (17 chapters)
Mastering Python Scientific Computing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The cryptography module


This SymPy module includes methods for both block ciphers and stream ciphers. Specifically, it includes the following ciphers:

  • Affine cipher

  • Bifid cipher

  • ElGamal encryption

  • Hill's cipher

  • Kid RSA

  • Linear feedback shift registers

  • RSA

  • Shift cipher

  • Substitution ciphers

  • Vigenere's cipher

This program demonstrates the RSA deciphering and enciphering on plain text:

from sympy.crypto.crypto import rsa_private_key, rsa_public_key, encipher_rsa, decipher_rsa
a, b, c = 11, 13, 17
rsa_private_key(a, b, c)
publickey = rsa_public_key(a, b, c)
pt = 8
encipher_rsa(pt, publickey)

privatekey = rsa_private_key(a, b, c)
ct = 112
decipher_rsa(ct, privatekey)

The following program performs Bifid cipher encryption and decryption on plain text and returns the cipher text:

from sympy.crypto.crypto import encipher_bifid6, decipher_bifid6
key = "encryptingit"
pt = "A very good book will be released in 2015"
encipher_bifid6(pt, key)
ct = "AENUIUKGHECNOIY27XVFPXR52XOXSPI0Q"
decipher_bifid6(ct, key)