Skip to content

JimmyZghendy/Crypto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

64 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Cryptography Project - S-DES & S-AES Implementation

A comprehensive implementation of Simplified Data Encryption Standard (S-DES) and Simplified Advanced Encryption Standard (S-AES) with support for multiple operation modes and various file types.

✨ Features

πŸ”’ Encryption Algorithms

  • S-DES (Simplified Data Encryption Standard) πŸ›‘οΈ

    • 10-bit key encryption
    • 8-bit block cipher
    • Educational implementation of DES principles
  • S-AES (Simplified Advanced Encryption Standard) πŸ”

    • 16-bit key encryption
    • 16-bit block cipher
    • Simplified version of AES for learning purposes

πŸ”„ Operation Modes

Both S-DES and S-AES support the following 5 operation modes:

  1. ECB (Electronic Codebook) πŸ“š

    • Each block encrypted independently
    • Simple but less secure for repetitive data
  2. CBC (Cipher Block Chaining) πŸ”—

    • Each block XORed with previous ciphertext
    • Requires initialization vector (IV)
  3. CFB (Cipher Feedback) πŸ”„

    • Stream cipher mode
    • Encryption of IV creates keystream
  4. OFB (Output Feedback) πŸ”

    • Stream cipher mode
    • IV encrypted repeatedly to generate keystream
  5. CTR (Counter) πŸ”’

    • Stream cipher mode
    • Counter encrypted to generate keystream

πŸ“ Supported File Types

  • Images: Process image files with encryption/decryption πŸ–ΌοΈ
  • Videos: Handle video file encryption (.mp4 format) πŸŽ₯
  • Text Files: Encrypt/decrypt text documents (.txt format) πŸ“„
  • JSON: Configuration and key files πŸ“‹

πŸš€ Additional Features

  • Brute Force Attack: Implement brute force decryption for text files πŸ’₯
  • Key Generation: Automatic key generation utilities πŸ”‘
  • File I/O: Robust file handling for various formats πŸ“‚

Project Structure πŸ“

Crypto/
β”œβ”€β”€ s-aes/ πŸ”
β”‚   β”œβ”€β”€ CBC.py          # πŸ”— Cipher Block Chaining mode
β”‚   β”œβ”€β”€ CFB.py          # πŸ”„ Cipher Feedback mode
β”‚   β”œβ”€β”€ CTR.py          # πŸ”’ Counter mode
β”‚   β”œβ”€β”€ ECB.py          # πŸ“š Electronic Codebook mode
β”‚   β”œβ”€β”€ OFB.py          # πŸ”„ Output Feedback mode
β”‚   β”œβ”€β”€ S-AES.json      # βš™οΈ Configuration file
β”‚   β”œβ”€β”€ S_AES_Decryption.py  # πŸ”“ Main decryption module
β”‚   β”œβ”€β”€ S_AES_Encryption.py  # πŸ”’ Main encryption module
β”‚   β”œβ”€β”€ key.json        # πŸ”‘ Key storage
β”‚   β”œβ”€β”€ text.txt        # πŸ“„ Sample text file
β”‚   β”œβ”€β”€ video.mp4       # πŸŽ₯ Sample video file
β”‚   └── Class Diagram1.jpg   # πŸ“Š Project documentation
β”‚
β”œβ”€β”€ s-des/ πŸ›‘οΈ
β”‚   β”œβ”€β”€ CBC.py          # πŸ”— Cipher Block Chaining mode
β”‚   β”œβ”€β”€ CFB.py          # πŸ”„ Cipher Feedback mode
β”‚   β”œβ”€β”€ CTR.py          # πŸ”’ Counter mode
β”‚   β”œβ”€β”€ ECB.py          # πŸ“š Electronic Codebook mode
β”‚   β”œβ”€β”€ OFB.py          # πŸ”„ Output Feedback mode
β”‚   β”œβ”€β”€ S-DES.json      # βš™οΈ Configuration file
β”‚   β”œβ”€β”€ S_DES_decryption.py  # πŸ”“ Main decryption module
β”‚   β”œβ”€β”€ S_DES_encryption.py  # πŸ”’ Main encryption module
β”‚   β”œβ”€β”€ text.txt        # πŸ“„ Sample text file
β”‚   β”œβ”€β”€ text_recovered.txt   # πŸ”„ Recovered text file
β”‚   β”œβ”€β”€ video.mp4       # πŸŽ₯ Sample video file
β”‚   └── Class Diagram1.jpg   # πŸ“Š Project documentation
β”‚
β”œβ”€β”€ .gitignore          # πŸ“ Git ignore rules
β”œβ”€β”€ README.md           # πŸ“– Project documentation
└── key.json            # πŸ”‘ Global key storage

πŸš€ Installation

  1. Clone the repository:
git clone [repository-url]
cd Crypto
  1. Install required dependencies:
pip install -r requirements.txt

πŸ’» Usage

S-AES Implementation πŸ”

Encryption πŸ”’

from S_AES_Encryption import encrypt_file

# Encrypt a text file
encrypt_file('input.txt', 'output.enc', key='your-16-bit-key', mode='CBC')

# Encrypt an image
encrypt_file('image.jpg', 'image.enc', key='your-16-bit-key', mode='ECB')

Decryption πŸ”“

from S_AES_Decryption import decrypt_file

# Decrypt a file
decrypt_file('encrypted.enc', 'decrypted.txt', key='your-16-bit-key', mode='CBC')

S-DES Implementation πŸ›‘οΈ

Basic Usage

from S_DES_encryption import s_des_encrypt
from S_DES_decryption import s_des_decrypt

# Encrypt/decrypt with S-DES
plaintext = "Hello"
key = "1010000010"  # 10-bit key
encrypted = s_des_encrypt(plaintext, key)
decrypted = s_des_decrypt(encrypted, key)

πŸ”§ Operation Modes

ECB Mode πŸ“š

from ECB import encrypt_ecb, decrypt_ecb
result = encrypt_ecb(data, key)

CBC Mode πŸ”—

from CBC import encrypt_cbc, decrypt_cbc
result = encrypt_cbc(data, key, iv)

CFB Mode πŸ”„

from CFB import encrypt_cfb, decrypt_cfb
result = encrypt_cfb(data, key, iv)

OFB Mode πŸ”

from OFB import encrypt_ofb, decrypt_ofb
result = encrypt_ofb(data, key, iv)

CTR Mode πŸ”’

from CTR import encrypt_ctr, decrypt_ctr
result = encrypt_ctr(data, key, counter)

πŸ’₯ Brute Force Attack

For educational purposes, implement brute force attacks on encrypted text:

def brute_force_text(encrypted_text, known_plaintext=None):
    """
    Attempt to decrypt text using brute force method πŸ”“πŸ’ͺ
    """
    # Implementation for trying all possible keys
    pass

πŸ“‚ File Format Support

Text Files (.txt) πŸ“„

  • Direct encryption/decryption of text content
  • Support for various encodings (UTF-8, ASCII)
  • Includes text_recovered.txt for brute force results

Images πŸ–ΌοΈ

  • Pixel-level encryption
  • Maintains image structure while encrypting pixel data
  • Supports common formats (JPEG, PNG)

Videos (.mp4) πŸŽ₯

  • Frame-by-frame encryption
  • Maintains video container structure
  • Encrypts video stream data

Security Notes

⚠️ Educational Purpose Only: This implementation is designed for educational purposes to understand cryptographic principles. Do not use for production security applications.

  • S-DES and S-AES are simplified versions with reduced security
  • Real-world applications should use proven cryptographic libraries
  • Keys should be generated using cryptographically secure random generators

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

Educational Resources

This project demonstrates:

  • Block cipher operation modes
  • Symmetric encryption principles
  • File handling in cryptographic contexts
  • Brute force attack methodologies
  • Key management practices

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Based on educational materials for cryptography courses
  • Implements simplified versions of industry-standard algorithms
  • Designed for learning and demonstration purposes

About

Project Info431: Crypto S-DES and S-AES. Spring 2025

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages