CrackingCodes.Ch16 package

Submodules

CrackingCodes.Ch16.PracticeQuestions module

Chapter 16 Practice Questions

Answers Chapter 16 Practice Questions via Python code.

CrackingCodes.Ch16.PracticeQuestions.main()[source]

CrackingCodes.Ch16.simpleSubCipher module

Simple Substitution Cipher

Provides functions that implement a substitution cipher.

CrackingCodes.Ch16.simpleSubCipher.LETTERS

String containing uppercase latin letters.

Type:str

Example

>>> import pythontutorials.books.CrackingCodes.Ch16.simpleSubCipher as simpleSubCipher
>>> key = simpleSubCipher.getRandomKey()  # key = 'VIAXLGJBKSZDUTRPYCEWNFHOMQ', in this example
>>> message = 'You\'d be surprised what you can live through.'
>>> simpleSubCipher.encryptMessage(key, message)
"Mrn'x il encpckelx hbvw mrn avt dkfl wbcrnjb"
CrackingCodes.Ch16.simpleSubCipher.decryptMessage(key: str, message: str) → str[source]

Substitution Cipher Decrypt

Wrapper function that decrypts given substitution cipher encrypted message with the given key.

Parameters:
  • key – String containing key used to decrypt substitution cipher.
  • message – String containing message to decrypt.
Returns:

Decrypted message.

CrackingCodes.Ch16.simpleSubCipher.encryptMessage(key: str, message: str) → str[source]

Substitution Cipher Encrypt

Wrapper function that encrypts given message with the given key using the substitution cipher.

Parameters:
  • key – String containing key used to encrypt with substitution cipher.
  • message – String containing message to encrypt.
Returns:

Encrypted message.

CrackingCodes.Ch16.simpleSubCipher.getRandomKey() → str[source]

Substitution cipher key generator

Generates a random key that can be used with the substitution cipher.

Returns:String with a random, valid key.
CrackingCodes.Ch16.simpleSubCipher.keyIsValid(key: str) → bool[source]

Checks key for validity.

Ensures key contains all letters in LETTERS.

Parameters:key – String containing key used to encrypt with substitution cipher.
Returns:True if key and LETTERS match, False otherwise.
CrackingCodes.Ch16.simpleSubCipher.main()[source]
CrackingCodes.Ch16.simpleSubCipher.translateMessage(key: str, message: str, mode: str) → str[source]

Substitution Cipher

Implements a substitution cipher that can encrypt or decrypt messages depending on the given mode.

Parameters:
  • key – String containing key used to decrypt/encrypt messages.
  • message – String containing message to decrypt/encrypt.
  • mode – String specifying whether to ‘encrypt’ or ‘decrypt’.
Returns:

Encrypted or decrypted message.

Module contents