Skip to main content

Enhanced Enigma Cipher Machine - Python Implementation

Project description

EnigmaEnhanced

Python 实现增强版恩尼格玛密码机

Enhanced Enigma Cipher Machine - Python Implementation

历史背景与现代演绎

Historical Context and Modern Interpretation

在密码学的历史长卷中,恩尼格玛密码机(Enigma)无疑是最具传奇色彩的篇章之一。这台由德国工程师Arthur Scherbius发明的机械加密设备,在二战期间曾被视为"不可破译"的通信保障,造就了人类密码学史上的重要里程碑。艾伦·图灵在布莱切利园领导的破译工作,不仅缩短了战争进程,更开启了现代计算机科学的先河。

In the grand tapestry of cryptography, the Enigma cipher machine stands as one of the most legendary chapters. Invented by German engineer Arthur Scherbius, this mechanical encryption device was considered "unbreakable" during WWII, becoming a crucial milestone in human cryptographic history. Alan Turing's codebreaking work at Bletchley Park not only shortened the war but also paved the way for modern computer science.

本项目是对这一历史经典的现代数字演绎,保留了恩尼格玛机核心的转子机制原理,同时融合了现代密码学技术:

This project is a modern digital interpretation of this historical classic, preserving the core rotor mechanism principle of the Enigma machine while incorporating modern cryptographic techniques:

1.密码学传承:保留经典的三转子+反射器结构,致敬历史原型 -Cryptographic Heritage: Maintains the classic three-rotor + reflector structure, paying homage to the historical prototype

2.现代增强:引入SHA-256哈希增强密钥派生,大幅提升安全性 -Modern Enhancement: Incorporates SHA-256 hashing for key derivation, significantly improving security

3.Unicode扩展:突破原始设备26字母限制,支持全字符集加密 -Unicode Extension: Breaks the 26-letter limitation of the original device, supporting full character set encryption

4.密钥管理:实现完善的密钥生成、存储和加载机制 -Key Management: Implements comprehensive key generation, storage, and loading mechanisms

"密码学不仅是保护信息的科学,更是人类智慧与创造力的永恒战场。" —— Whitfield Diffie(公钥密码学先驱) "Cryptography is not just a science of protecting information; it is an eternal battlefield of human ingenuity." — Whitfield Diffie (Pioneer of Public Key Cryptography)

功能亮点

Key Features

python

class EnigmaEnhanced:
    def __init__(self):
        # 初始化增强版恩尼格玛机
        # Initialize enhanced Enigma machine
        self.key = None
        self.print_help()

1.增强密钥系统 Enhanced Key System

HKDF式密钥派生算法(基于SHA-256) -HKDF-like key derivation algorithm (based on SHA-256)

256位加密种子生成(符合现代安全标准) -256-bit encryption seed generation (meets modern security standards)

三转子配置,每个转子含256个位置(支持全字节范围) -Three-rotor configuration, each with 256 positions (supports full byte range)

2.智能命令界面 Intelligent Command Interface

python

# 命令处理示例
# Command processing example
if user_input.startswith("/"):
    # 命令解析逻辑
    # Command parsing logic
    if command == "genkey":
        enigma.generate_key(filename)

3.错误防御机制 Error Defense Mechanism

*密钥不匹配检测 -Key mismatch detection

*密文损坏识别 -Ciphertext corruption recognition

*异常处理保障程序健壮性 -Exception handling ensures program robustness

*多语言支持 -Multilingual Support

*完整UTF-8编码支持 -Full UTF-8 encoding support

*中英双语用户界面 -Bilingual Chinese-English user interface

*全球化错误提示 -Globalized error messages

应用场景

Application Scenarios

  1. 密码学教育 Cryptography Education

*生动演示转子密码机工作原理 -Vivid demonstration of rotor cipher machine working principles

*对比古典密码与现代加密技术差异 -Comparison of classical and modern encryption techniques

*密码分析实战平台(可扩展为CTF挑战) -Practical platform for cryptanalysis (extendable to CTF challenges)

  1. 安全通信 Secure Communication

python

# 加密过程核心
# Core encryption process
def _process_byte(self, byte_val: int, rotors: List[List[int]], reflector: List[int]) -> int:
    # 转子加密流程
    # Rotor encryption process
    for rotor in rotors:
        byte_val = rotor[byte_val]
    byte_val = reflector[byte_val]
    for rotor in reversed(rotors):
        byte_val = rotor.index(byte_val)
    return byte_val

*安全聊天应用的基础加密层 -Basic encryption layer for secure chat applications

*敏感信息临时保护(配合安全信道交换密钥) -Temporary protection of sensitive information (with secure key exchange)

*数字版权管理(轻量级内容保护) -Digital rights management (lightweight content protection)

  1. 文化遗产保护 Cultural Heritage Preservation

*博物馆互动展示系统 -Museum interactive display systems

*密码学历史数字体验 -Digital experience of cryptographic history

*二战密码战教学工具 -Teaching tool for WWII cryptography warfare

  1. 创意应用开发 Creative Application Development

*神秘主题游戏加密引擎 -Encryption engine for mystery-themed games

*数字艺术作品的隐藏信息层 -Hidden information layer for digital artworks

*诗歌/文学作品的加密创作 -Encrypted creation of poetry/literary works

技术优势

Technical Advantages

1.密码增强设计 Cryptographic Enhancement Design

python

def _derive_key(self, seed: bytes, length: int) -> bytes:
    # HKDF式密钥派生
    # HKDF-like key derivation
    key = b''
    salt = b'enigma_salt'
    counter = 0
    while len(key) < length:
        key += hashlib.sha256(salt + seed + counter.to_bytes(4, 'big')).digest()
        counter += 1
    return key[:length]

2.密码混淆技术 Cryptographic Obfuscation Technique

python

# 加密后混淆处理
# Post-encryption obfuscation
key_material = self._derive_key(seed, len(processed_bytes))
for i, byte_val in enumerate(processed_bytes):
    encrypted.append(byte_val ^ key_material[i])

3.完整Unicode支持 Full Unicode Support

python

# UTF-8编码处理
# UTF-8 encoding processing
text_bytes = text.encode('utf-8')
# ...
return bytes(result_bytes).decode('utf-8')

使用示例

Usage Example

bash

> /genkey secret_key.json
密钥已生成并保存到 secret_key.json
Key has been generated and saved to secret_key.json

> 你好,世界!
加密结果: ENC:7Hj8F3kL9aB2cX5z...
Encryption result: ENC:7Hj8F3kL9aB2cX5z...

> ENC:7Hj8F3kL9aB2cX5z...
解密结果: 你好,世界!
Decryption result: 你好,世界!

项目意义

Project Significance

本实现架起了密码学历史与现代技术的桥梁,在保留恩尼格玛机精妙机械设计思想的同时,赋予其适应数字时代的新生命。正如密码学家Bruce Schneier所言:"安全是一个过程,而非产品。" 本项目旨在延续这一过程,让历史智慧在现代技术中焕发新生。

This implementation bridges cryptographic history with modern technology, preserving the ingenious mechanical design philosophy of the Enigma machine while giving it new life adapted to the digital age. As cryptographer Bruce Schneier said: "Security is a process, not a product." This project aims to continue this process, revitalizing historical wisdom with modern technology.

免责声明: 本工具为教育目的设计,不应用于实际安全通信。现代加密应使用AES、RSA等标准化算法。 Disclaimer: This tool is designed for educational purposes and should not be used for actual secure communication. Modern encryption should use standardized algorithms such as AES or RSA.

欢迎贡献代码!让我们共同守护数字世界的安全与隐私。 Welcome to contribute code! Let's protect the security and privacy of the digital world together.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

enigmaenhanced-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

EnigmaEnhanced-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file enigmaenhanced-0.1.0.tar.gz.

File metadata

  • Download URL: enigmaenhanced-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for enigmaenhanced-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd766930b0f8bb7fecc386f485886716fd9c5a9f1a1577e0fa82a84048c4f7c8
MD5 d53b309b5e8e92ecf41f3bdecca88ad4
BLAKE2b-256 6e3f37d30a7e35c8cc61fc4a51e849e220b8ef46663db09f77aa681272712bbb

See more details on using hashes here.

File details

Details for the file EnigmaEnhanced-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: EnigmaEnhanced-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for EnigmaEnhanced-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 828dc317843beca53d3746a150fb9f609085be6f0fbb350b0c5a475b606768af
MD5 7644cabcc023af17099e1db41db67e21
BLAKE2b-256 9f00cdd06be438b3dc2c33c96ccf7077235e305806fe861d5ce46e9857dc442b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page