Skip to main content

Educational cryptography and network security concepts in Python

Project description

crypto-12

A pure-Python educational package covering 21 cryptography and network security concepts.
No external dependencies. Works with Python 3.8+.


๐Ÿ“ฆ Package Structure

crypto-12/
โ”‚
โ”œโ”€โ”€ crypto_12/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ caesar_cipher.py
โ”‚   โ”œโ”€โ”€ monoalphabetic_cipher.py
โ”‚   โ”œโ”€โ”€ vigenere_cipher.py
โ”‚   โ”œโ”€โ”€ playfair_cipher.py
โ”‚   โ”œโ”€โ”€ hill_cipher.py
โ”‚   โ”œโ”€โ”€ rail_fence_cipher.py
โ”‚   โ”œโ”€โ”€ row_column_transposition.py
โ”‚   โ”œโ”€โ”€ rsa_demo.py
โ”‚   โ”œโ”€โ”€ diffie_hellman_demo.py
โ”‚   โ”œโ”€โ”€ sha1_hash.py
โ”‚   โ”œโ”€โ”€ md5_hash.py
โ”‚   โ”œโ”€โ”€ gcd_euclidean.py
โ”‚   โ”œโ”€โ”€ extended_euclidean.py
โ”‚   โ”œโ”€โ”€ multiplicative_inverse.py
โ”‚   โ”œโ”€โ”€ affine_cipher.py
โ”‚   โ”œโ”€โ”€ columnar_transposition.py
โ”‚   โ”œโ”€โ”€ simple_permutation.py
โ”‚   โ”œโ”€โ”€ otp_cipher.py
โ”‚   โ”œโ”€โ”€ frequency_analysis.py
โ”‚   โ”œโ”€โ”€ sql_injection_demo.py
โ”‚   โ””โ”€โ”€ nmap_scan_demo.py
โ”‚
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ README.md

๐Ÿš€ Installation

Option 1 โ€” Install directly (editable/development mode)

pip install .

Option 2 โ€” Build a distributable wheel, then install

# Install build tool
pip install build

# Build the package
python -m build

# Install the built wheel
pip install dist/crypto_12-0.1.0-py3-none-any.whl

๐Ÿ”ง Usage

After installing, you can import and use any module:

from crypto_12 import caesar_cipher

caesar_cipher.run()

Or call individual functions:

from crypto_12.caesar_cipher import encrypt, decrypt

encrypted = encrypt("HELLO WORLD", 3)
decrypted = decrypt(encrypted, 3)
print(encrypted)  # KHOOR ZRUOG
print(decrypted)  # HELLO WORLD

๐Ÿ“š Module Reference

Substitution Ciphers

Module Description
caesar_cipher Shift cipher โ€” each letter shifted by a fixed amount
monoalphabetic_cipher Arbitrary fixed substitution using a 26-letter key alphabet
vigenere_cipher Polyalphabetic cipher using a repeating keyword
playfair_cipher Digraph cipher using a 5ร—5 key matrix
hill_cipher Linear algebra cipher using a 2ร—2 invertible matrix (mod 26)
affine_cipher C = (a*P + b) mod 26 with modular inverse for decryption

Transposition Ciphers

Module Description
rail_fence_cipher Zig-zag pattern writing across N rails
row_column_transposition Write in rows, read columns sorted by key
columnar_transposition Column reordering based on alphabetical key ranking
simple_permutation Rearranges character positions within fixed-length blocks

Public Key / Key Exchange

Module Description
rsa_demo Simplified RSA: key generation, encrypt/decrypt with small primes
diffie_hellman_demo DH key exchange: shared secret agreement over public channel

Hashing

Module Description
sha1_hash Pure-Python SHA-1 implementation (160-bit hash)
md5_hash Pure-Python MD5 implementation (128-bit hash)

Number Theory / Math Utilities

Module Description
gcd_euclidean GCD with step-by-step Euclidean trace
extended_euclidean Extended GCD returning Bezout coefficients
multiplicative_inverse Modular inverse: a * x โ‰ก 1 (mod m)

Cryptanalysis

Module Description
frequency_analysis Letter frequency counter + Caesar shift guesser
otp_cipher One-Time Pad simulation using XOR + random key

Security Awareness (Safe Demos)

Module Description
sql_injection_demo Explains SQL injection with safe/vulnerable query comparison
nmap_scan_demo Nmap command reference; prints examples only, no real scanning

โ–ถ๏ธ Running Individual Modules Interactively

Each module has a run() function with interactive prompts:

python -c "from crypto_12 import vigenere_cipher; vigenere_cipher.run()"
python -c "from crypto_12 import rsa_demo; rsa_demo.run()"
python -c "from crypto_12 import frequency_analysis; frequency_analysis.run()"

โš ๏ธ Disclaimer

  • The SHA-1 and MD5 implementations are educational and should not be used for security-critical applications.
  • The SQL injection demo performs no real database queries.
  • The Nmap demo performs no actual network scans.
  • RSA and Diffie-Hellman use small numbers for clarity; real implementations require much larger primes.

๐Ÿ“„ License

MIT License โ€” free to use for learning and educational purposes.

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

crypto_12-0.1.1.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

crypto_12-0.1.1-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file crypto_12-0.1.1.tar.gz.

File metadata

  • Download URL: crypto_12-0.1.1.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for crypto_12-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4a9006aa6610135ef2dfbdea6a7b9ecf061d24d3c63debf3e0554cf522e622a0
MD5 77128aadf7b0ee61cde51be10e1952cd
BLAKE2b-256 c578800e518d9d680419e4586ee2b7f63f681fce57d7bedcf062ad3b3af0c7af

See more details on using hashes here.

File details

Details for the file crypto_12-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: crypto_12-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for crypto_12-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a1377abcae5daa665530051233f1dd7f3ab2ce4d419c8d03c4fef5fa8764b1e3
MD5 6b9a301210c4a0e0549ec330eff84e99
BLAKE2b-256 892baa3bf82f1fc5c2b2a0534cf5e23a126ffa183fe546dc9d30ae75aa81158e

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