Cryptography with Python Tutorial
Useful Resources
Selected Reading
- Hacking RSA Cipher
- RSA Cipher Decryption
- RSA Cipher Encryption
- Creating RSA Keys
- Understanding RSA Algorithm
- Symmetric & Asymmetric Cryptography
- Implementation of One Time Pad Cipher
- One Time Pad Cipher
- Implementing Vignere Cipher
- Understanding Vignere Cipher
- Python Modules of Cryptography
- Decryption of Simple Substitution Cipher
- Testing of Simple Substitution Cipher
- Simple Substitution Cipher
- Hacking Monoalphabetic Cipher
- Affine Ciphers
- Multiplicative Cipher
- XOR Process
- Base64 Encoding & Decoding
- Decryption of files
- Encryption of files
- Decryption of Transposition Cipher
- Encryption of Transposition Cipher
- Transposition Cipher
- ROT13 Algorithm
- Caesar Cipher
- Reverse Cipher
- Python Overview and Installation
- Double Strength Encryption
- Overview
- Home
Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Affine Ciphers
Cryptography with Python - Affine Cipher
Affine Cipher is the combination of Multippcative Cipher and Caesar Cipher algorithm. The basic implementation of affine cipher is as shown in the image below −
In this chapter, we will implement affine cipher by creating its corresponding class that includes two basic functions for encryption and decryption.
Code
You can use the following code to implement an affine cipher −
class Affine(object): DIE = 128 KEY = (7, 3, 55) def __init__(self): pass def encryptChar(self, char): K1, K2, kI = self.KEY return chr((K1 * ord(char) + K2) % self.DIE) def encrypt(self, string): return "".join(map(self.encryptChar, string)) def decryptChar(self, char): K1, K2, KI = self.KEY return chr(KI * (ord(char) - K2) % self.DIE) def decrypt(self, string): return "".join(map(self.decryptChar, string)) affine = Affine() print affine.encrypt( Affine Cipher ) print affine.decrypt( *18?FMT )
Output
You can observe the following output when you implement an affine cipher −
The output displays the encrypted message for the plain text message Affine Cipher and decrypted message for the message sent as input abcdefg.
Advertisements