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 1: Understand the Components
  • Step 2: Encryption Process
  • Step 3: Decryption Process
  • Practical Example
  • Encryption
  • Step 2: Encrypt Each Letter:
  • Decryption
  • Step 4: Add Complexity (Optional)
  • Step 5: Python Code
  • Output
  1. Cybersecurity
  2. Classical Ciphers

Alberti Cipher

Nerd Cafe

PreviousGronsfeld CipherNextHill Cipher

Last updated 1 month ago

The Alberti Cipher is one of the earliest polyalphabetic ciphers, invented by Leon Battista Alberti in the 15th century. It uses two concentric disks to encrypt and decrypt messages.

Here’s a step-by-step explanation with a practical example.

Step 1: Understand the Components

Two Disks:

  • Outer Disk: Contains uppercase letters (A-Z) and possibly numbers or symbols.

  • Inner Disk: Contains lowercase letters (a-z) and possibly numbers or symbols.

  • The inner disk rotates independently of the outer disk.

Key:

  • The initial alignment of the disks (e.g., Outer Disk 'A' matches Inner Disk 'a') is the starting key.

  • The cipher can also periodically change alignment during encryption to increase complexity.

Step 2: Encryption Process

Align the Disks:

  • Decide the initial key (e.g., Outer Disk 'A' aligns with Inner Disk 'm').

Substitute Letters:

  • For each letter in the plaintext, find it on the outer disk and replace it with the corresponding letter from the inner disk.

Change the Alignment (Optional):

  • Periodically rotate the inner disk to a new position, as agreed upon in the cipher key, for added security.

Step 3: Decryption Process

Align the Disks:

  • Use the same initial key and alignment used during encryption.

Reverse Substitution:

  • For each letter in the ciphertext, find it on the inner disk and replace it with the corresponding letter from the outer disk.

Adjust for Changes:

  • If the alignment was changed during encryption, synchronize the same changes during decryption.

Practical Example

  • Scenario: Encrypt the plaintext message: HELLO.

  • Outer Disk: A-Z (uppercase)

  • Inner Disk: a-z (lowercase)

  • Initial Key: Outer Disk 'A' aligns with Inner Disk 'm'.

Encryption

Step 1: Align the Disks: Outer 'A' aligns with Inner 'm'.

Outer Disk: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Inner Disk: mnopqrstuvwxyzabcdefghijklm

Step 2: Encrypt Each Letter:

  • H → Find 'H' on the Outer Disk. It's aligned with 't' on the Inner Disk.

  • E → Find 'E' on the Outer Disk. It's aligned with 'q'.

  • L → Find 'L' on the Outer Disk. It's aligned with 'x'.

  • L → Same as above, aligns with 'x'.

  • O → Find 'O' on the Outer Disk. It's aligned with 'a'.

Ciphertext: tqxxa.

Decryption

Step 1: Align the Disks: Use the same initial key: Outer 'A' aligns with Inner 'm'.

Outer Disk: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Inner Disk: mnopqrstuvwxyzabcdefghijklm

Step 2: Decrypt Each Letter:

  • t → Find 't' on the Inner Disk. It's aligned with 'H' on the Outer Disk.

  • q → Find 'q' on the Inner Disk. It's aligned with 'E'.

  • x → Find 'x' on the Inner Disk. It's aligned with 'L'.

  • x → Same as above, aligns with 'L'.

  • a → Find 'a' on the Inner Disk. It's aligned with 'O'.

Decrypted Text: HELLO.

Step 4: Add Complexity (Optional)

To make the cipher more secure:

  • Periodically rotate the inner disk after encrypting certain letters.

  • Use symbols or numbers in the disks for added complexity.

Step 5: Python Code

The Python code implements the Alberti Cipher with functions for encryption and decryption.

# Alberti Cipher Implementation

def generate_disks():
    outer_disk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    inner_disk = "mnopqrstuvwxyzabcdefghijkl"
    return outer_disk, inner_disk

def encrypt_alberti(plaintext, initial_key):
    outer_disk, inner_disk = generate_disks()
    ciphertext = ""

    # Align the disks using the initial key
    shift = outer_disk.index(initial_key.upper())
    inner_disk = inner_disk[shift:] + inner_disk[:shift]

    for char in plaintext:
        if char.isalpha():
            index = outer_disk.index(char.upper())
            cipher_char = inner_disk[index]
            ciphertext += cipher_char
        else:
            ciphertext += char  # Keep non-alphabetic characters as is

    return ciphertext

def decrypt_alberti(ciphertext, initial_key):
    outer_disk, inner_disk = generate_disks()
    plaintext = ""

    # Align the disks using the initial key
    shift = outer_disk.index(initial_key.upper())
    inner_disk = inner_disk[shift:] + inner_disk[:shift]

    for char in ciphertext:
        if char.isalpha():
            index = inner_disk.index(char)
            plain_char = outer_disk[index]
            plaintext += plain_char
        else:
            plaintext += char  # Keep non-alphabetic characters as is

    return plaintext

# Example usage
initial_key = "A"  # Outer 'A' aligns with Inner 'm'
plaintext = "HELLO"
ciphertext = encrypt_alberti(plaintext, initial_key)

decrypted_text = decrypt_alberti(ciphertext, initial_key)

print(f"Plaintext: {plaintext}")
print(f"Ciphertext: {ciphertext}")
print(f"Decrypted Text: {decrypted_text}")

Output

Plaintext: HELLO
Ciphertext: tqxxa
Decrypted Text: HELLO