Python Encyclopedia for Academics
  • Course Outline
  • Artificial Intelligence
    • Data Science Foundation
      • Python Programming
        • Introduction and Basics
          • Variables
          • Print Function
          • Input From User
          • Data Types
          • Type Conversion
        • Operators
          • Arithmetic Operators
          • Relational Operators
          • Bitwise Operators
          • Logical Operators
          • Assignment Operators
          • Compound Operators
          • Membership Operators
          • Identity Operators
      • Numpy
        • Vectors, Matrix
        • Operations on Matrix
        • Mean, Variance, and Standard Deviation
        • Reshaping Arrays
        • Transpose and Determinant of Matrix
      • Pandas
        • Series and DataFrames
        • Slicing, Rows, and Columns
        • Operations on DataFrames
        • Different wayes to creat DataFrame
        • Read, Write Operations with CSV files
      • Matplotlib
        • Graph Basics
        • Format Strings in Plots
        • Label Parameters, Legend
        • Bar Chart, Pie Chart, Histogram, and Scatter Plot
  • Machine Learning Algorithms
    • Regression Analysis In ML
      • Regression Analysis in Machine Learning
      • Proof of Linear Regression Formulas
      • Simple Linear Regression Implementation
      • Multiple Linear Regression
      • Advertising Dataset Example
      • Bike Sharing Dataset
      • Wine Quality Dataset
      • Auto MPG Dataset
    • Classification Algorithms in ML
      • Proof of Logistic Regression
      • Simplified Mathematical Proof of SVM
      • Iris Dataset
  • Machine Learning Laboratory
    • Lab 1: Titanic Dataset
      • Predicting Survival on the Titanic with Machine Learning
    • Lab 2: Dow Jones Index Dataset
      • Dow Jones Index Predictions Using Machine Learning
    • Lab 3: Diabetes Dataset
      • Numpy
      • Pandas
      • Matplotlib
      • Simple Linear Regression
      • Simple Non-linear Regression
      • Performance Matrix
      • Preprocessing
      • Naive Bayes Classification
      • K-Nearest Neighbors (KNN) Classification
      • Decision Tree & Random Forest
      • SVM Classifier
      • Logistic Regression
      • Artificial Neural Network
      • K means Clustering
    • Lab 4: MAGIC Gamma Telescope Dataset
      • Classification in ML-MAGIC Gamma Telescope Dataset
    • Lab 5: Seoul Bike Sharing Demand Dataset
      • Regression in ML-Seoul Bike Sharing Demand Dataset
    • Lab 6: Medical Cost Personal Datasets
      • Predict Insurance Costs with Linear Regression in Python
    • Lab 6: Predict The S&P 500 Index With Machine Learning And Python
      • Predict The S&P 500 Index With Machine Learning And Python
  • Artificial Neural Networks
    • Biological Inspiration vs. Artificial Neurons
    • Review linear algebra and calculus essentials for ANNs
    • Activation Function
  • Mathematics
    • Pre-Calculus
      • Factorials
      • Roots of Polynomials
      • Complex Numbers
      • Polar Coordinates
      • Graph of a Function
    • Calculus 1
      • Limit of a Function
      • Derivative of Function
      • Critical Points
      • Indefinite Integrals
  • Calculus 2
    • 3D Coordinates and Vectors
    • Vectors and Vector Operations
    • Lines and Planes in Space (3D)
    • Partial Derivatives
    • Optimization Problems (Maxima/Minima) in Multivariable Functions
    • Gradient Vectors
  • Engineering Mathematics
    • Laplace Transform
  • Electrical & electronics Eng
    • Resistor
      • Series Resistors
      • Parallel Resistors
    • Nodal Analysis
      • Example 1
      • Example 2
    • Transient State
      • RC Circuit Equations in the s-Domain
      • RL Circuit Equations in the s-Domain
      • LC Circuit Equations in the s-Domain
      • Series RLC Circuit with DC Source
  • Computer Networking
    • Fundamental
      • IPv4 Addressing
      • Network Diagnostics
  • Cybersecurity
    • Classical Ciphers
      • Caesar Cipher
      • Affine Cipher
      • Atbash Cipher
      • Vigenère Cipher
      • Gronsfeld Cipher
      • Alberti Cipher
      • Hill Cipher
Powered by GitBook
On this page
  • Step-by-Step Explanation
  • Step 2: Encrypt a Message
  • Step 3: Decrypt a Message
  • Practical Python Implementation
  1. Cybersecurity
  2. Classical Ciphers

Atbash Cipher

Nerd Cafe

The Atbash Cipher is a substitution cipher that replaces each letter of the alphabet with its reverse counterpart. For example, in the English alphabet, 'A' is replaced with 'Z', 'B' with 'Y', and so on.

Let's go through the steps to encrypt and decrypt a message using the Atbash Cipher with a practical example.

Step-by-Step Explanation

Step 1: Understand the Atbash Cipher Rule

  • Write down the English alphabet:

Alphabet:  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Reverse:   Z Y X W V U T S R Q P O N M L K J I H G F E D C B A

Each letter in the message is replaced by its counterpart in the reverse alphabet.

Step 2: Encrypt a Message

Suppose we want to encrypt the message: HELLO.

  1. For each letter in "HELLO", find its reverse counterpart:

  • H → S

  • E → V

  • L → O

  • L → O

  • O → L

  1. Replace the letters to get the ciphertext: SVOOL.

Step 3: Decrypt a Message

Decrypting is the same as encrypting because the Atbash Cipher is symmetric:

  1. For each letter in "SVOOL", find its reverse counterpart:

  • S → H

  • V → E

  • O → L

  • O → L

  • L → O

Replace the letters to get the original plaintext: HELLO.

Practical Python Implementation

Here’s how you can implement the Atbash Cipher in Python:

def atbash_cipher(text):
    # Define the alphabet
    alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    reverse_alphabet = alphabet[::-1]  # Reverse the alphabet
    
    # Create a mapping for the cipher
    atbash_mapping = {alphabet[i]: reverse_alphabet[i] for i in range(len(alphabet))}
    
    # Encrypt/Decrypt the text
    result = ''
    for char in text.upper():  # Convert to uppercase
        if char in atbash_mapping:
            result += atbash_mapping[char]
        else:
            result += char  # Keep non-alphabet characters unchanged
    return result

# Example Usage
plaintext = "HELLO"
ciphertext = atbash_cipher(plaintext)
print("Ciphertext:", ciphertext)  # Output: SVOOL

# Decrypting is the same process
decrypted_text = atbash_cipher(ciphertext)
print("Decrypted Text:", decrypted_text)  # Output: HELLO

Output:

Ciphertext: SVOOL
Decrypted Text: HELLO
PreviousAffine CipherNextVigenère Cipher

Last updated 1 month ago