Skip to main content

Multi-algorithm encryption library supporting Adjacent Swap, XOR+Base64, and AES-256-GCM

Project description

Multilingual Encryption-Decryption System

A comprehensive collection of three cross-language encryption implementations ranging from educational demos to production-grade security. All methods produce identical outputs across Python and JavaScript.

๐Ÿ” Available Encryption Methods

1. ๐Ÿ”„ Adjacent Character Swap (Simple)

Educational algorithm for learning encryption basics

  • Security: Very Low (for learning only)
  • Files: encrypt.py, encrypt.js, adjacent_swap.html

2. ๐Ÿ”’ XOR+Base64 Cipher (Key-Based)

Basic obfuscation with key requirement

  • Security: Low-Medium (basic obfuscation)
  • Files: xor_encrypt.py, xor_encrypt.js, xor_base64.html

3. ๐Ÿ›ก๏ธ AES-256-GCM (Production-Grade)

Military-level encryption for real security

  • Security: Very High (production ready)
  • Files: aes_encrypt.py, aes_encrypt.js, aes_encryption.html

๐Ÿš€ Quick Start

Interactive Demos

Open index.html in your browser to try all three methods with a beautiful UI!

Documentation

Live Demo

๐ŸŒ Try it online (if deployed)


๐Ÿ“Š Quick Comparison

Feature Adjacent Swap XOR+Base64 AES-256-GCM
Security Very Low Low-Medium Very High
Use Case Learning Obfuscation Production
Key Required Optional Required Required
Output Plain text Base64 Base64 JSON
Standards - - NIST Approved
Real Security โŒ โŒ โœ…

๐ŸŽฏ Installation & Usage

Prerequisites

Python:

# For AES-256 only
pip install cryptography

JavaScript:

  • Node.js 12+ (for CLI)
  • Modern browser (for web demos)

Run Tests

# Adjacent Character Swap
python encrypt.py
node encrypt.js

# XOR+Base64
python xor_encrypt.py
node xor_encrypt.js

# AES-256-GCM
python aes_encrypt.py
node aes_encrypt.js

All tests should pass with identical cross-language outputs! โœ…


๐Ÿ“– Usage Examples

1. Adjacent Character Swap (Learning)

๐Ÿ“– Usage Examples

1. Adjacent Character Swap (Learning)

Features: โœ… Cross-Language Compatible: Identical encryption output in Python, JavaScript
โœ… Deterministic: Same input always produces the same output
โœ… No Dependencies: Pure implementation
โœ… Unicode Support: Works with emojis, international characters
โœ… Optional Seeding: Add numeric seed for customizable encryption

Python:

python encrypt.py

JavaScript:

node encrypt.js

Web Demo: Open adjacent_swap.html in your browser


2. XOR+Base64 Cipher (Obfuscation)

Features: โœ… Key-Based: Requires encryption key
โœ… Base64 Output: Binary-safe encoding
โœ… Cross-Language: Identical outputs
โœ… Better than Simple Swap: Moderate security

Python:

python xor_encrypt.py

JavaScript:

node xor_encrypt.js

Web Demo: Open xor_base64.html in your browser


3. AES-256-GCM (Production Security)

Features: โœ… Military-Grade: AES-256 in GCM mode
โœ… NIST Approved: Government standard
โœ… Authenticated: Tamper detection included
โœ… PBKDF2: 100,000 iterations for key derivation
โœ… Production Ready: Real security for sensitive data

Installation:

pip install cryptography

Python:

python aes_encrypt.py

JavaScript:

node aes_encrypt.js

Web Demo: Open aes_encryption.html in your browser


๐Ÿ Python Code Examples

Adjacent Swap

from encrypt import encrypt, decrypt

encrypted = encrypt("bibek")
print(encrypted)  # Output: ibebk

decrypted = decrypt("ibebk")
print(decrypted)  # Output: bibek

# With seed
encrypted_seed = encrypt("bibek", 2)
print(encrypted_seed)  # Output: keibb

XOR+Base64

from xor_encrypt import xor_encrypt, xor_decrypt

encrypted = xor_encrypt("bibek", "secret")
print(encrypted)  # Output: EQwBFw4=

decrypted = xor_decrypt("EQwBFw4=", "secret")
print(decrypted)  # Output: bibek

AES-256-GCM

from aes_encrypt import aes_encrypt, aes_decrypt, generate_key

# Password-based
encrypted = aes_encrypt("sensitive data", "MyStr0ngP@ssw0rd")
decrypted = aes_decrypt(encrypted, "MyStr0ngP@ssw0rd")

# Key-based
key = generate_key()
encrypted = aes_encrypt_with_key("secret message", key)
decrypted = aes_decrypt_with_key(encrypted, key)

๐ŸŸจ JavaScript Code Examples

Adjacent Swap

const { encrypt, decrypt } = require('./encrypt.js');

const encrypted = encrypt("bibek");
console.log(encrypted);  // Output: ibebk

const decrypted = decrypt("ibebk");
console.log(decrypted);  // Output: bibek

// With seed
const encryptedSeed = encrypt("bibek", 2);
console.log(encryptedSeed);  // Output: keibb

XOR+Base64

const { xorEncrypt, xorDecrypt } = require('./xor_encrypt.js');

const encrypted = xorEncrypt("bibek", "secret");
console.log(encrypted);  // Output: EQwBFw4=

const decrypted = xorDecrypt("EQwBFw4=", "secret");
console.log(decrypted);  // Output: bibek

AES-256-GCM

const { aesEncrypt, aesDecrypt, generateKey } = require('./aes_encrypt.js');

// Password-based (async)
(async () => {
    const encrypted = await aesEncrypt("sensitive data", "MyStr0ngP@ssw0rd");
    const decrypted = await aesDecrypt(encrypted, "MyStr0ngP@ssw0rd");
    
    // Key-based
    const key = await generateKey();
    const encrypted2 = await aesEncryptWithKey("secret", key);
    const decrypted2 = await aesDecryptWithKey(encrypted2, key);
})();

๐ŸŒ Web Interface

All three encryption methods include interactive HTML demos with:

  • โœจ Beautiful gradient UI
  • ๐Ÿ“‹ One-click copy to clipboard
  • ๐Ÿ“ฑ Responsive design (mobile-friendly)
  • โšก Real-time encryption/decryption
  • ๐Ÿ“š Built-in example test cases
  • ๐ŸŽจ Method-specific color themes

Getting Started:

  1. Open index.html in your browser
  2. Choose your encryption method
  3. Start encrypting!

Features:

  • No server required (runs entirely in browser)
  • No installation needed for demos
  • Cross-browser compatible
  • Clean, modern interface

๐Ÿ”’ Security Recommendations

โš ๏ธ DO NOT USE for Real Security:

  • โŒ Adjacent Character Swap - Educational only
  • โŒ XOR+Base64 - Basic obfuscation only

โœ… USE for Real Security:

  • โœ… AES-256-GCM - Production-grade encryption
    • Suitable for sensitive data
    • Meets compliance standards (GDPR, HIPAA, PCI-DSS)
    • NIST approved
    • Authenticated encryption with tamper detection

For Production Use:

  • Use strong passwords (16+ characters)
  • Implement proper key management
  • Use HTTPS/TLS for data transmission
  • Never hardcode keys in source code
  • Rotate keys periodically
  • Follow OWASP security guidelines

๐Ÿงช Testing & Verification

All implementations include comprehensive test suites:

Test Coverage

  • โœ… Basic encryption/decryption
  • โœ… Unicode and emoji support
  • โœ… Wrong password/key detection
  • โœ… Empty string handling
  • โœ… Special characters
  • โœ… Long text processing
  • โœ… Cross-language compatibility

Cross-Language Verification

Verify identical outputs:

# Adjacent Swap
python -c "from encrypt import encrypt; print(encrypt('test'))"
node -e "const {encrypt} = require('./encrypt.js'); console.log(encrypt('test'));"
# Both output: etts

# XOR+Base64
python -c "from xor_encrypt import xor_encrypt; print(xor_encrypt('hello', 'key'))"
node -e "const {xorEncrypt} = require('./xor_encrypt.js'); console.log(xorEncrypt('hello', 'key'));"
# Both output: AwAVBwo=

๐Ÿ“‚ Project Structure

encryption/
โ”œโ”€โ”€ index.html                 # Landing page with method selection
โ”œโ”€โ”€ adjacent_swap.html         # Adjacent swap demo
โ”œโ”€โ”€ xor_base64.html           # XOR+Base64 demo
โ”œโ”€โ”€ aes_encryption.html       # AES-256 demo
โ”œโ”€โ”€ encrypt.py                # Adjacent swap (Python)
โ”œโ”€โ”€ encrypt.js                # Adjacent swap (JavaScript)
โ”œโ”€โ”€ xor_encrypt.py            # XOR+Base64 (Python)
โ”œโ”€โ”€ xor_encrypt.js            # XOR+Base64 (JavaScript)
โ”œโ”€โ”€ aes_encrypt.py            # AES-256-GCM (Python)
โ”œโ”€โ”€ aes_encrypt.js            # AES-256-GCM (JavaScript)
โ”œโ”€โ”€ README.md                 # This file
โ”œโ”€โ”€ ALGORITHM.md              # Adjacent swap algorithm details
โ”œโ”€โ”€ XOR_README.md             # XOR+Base64 documentation
โ”œโ”€โ”€ AES_README.md             # AES-256 documentation
โ”œโ”€โ”€ COMPARISON.md             # Side-by-side comparison
โ”œโ”€โ”€ QUICKSTART.md             # Quick start guide
โ””โ”€โ”€ instruction.md            # Original project specifications

๐Ÿ› ๏ธ Requirements

Python

  • Python 3.6+ (no dependencies for basic methods)
  • cryptography library for AES-256 only

JavaScript

  • Node.js 12+ (for CLI usage)
  • Modern browser with Web Crypto API (for AES-256 in browser)
  • No external dependencies

๐Ÿ“ Notes

```

Interactive Mode (Node.js)

Uncomment the last line in encrypt.js:

if (typeof require !== 'undefined' && require.main === module) {
    runTests();
    interactiveMode();  // Uncomment this line
}

๐Ÿงช Test Cases

Basic Test: "bibek"

| Language | Input | Encrypted | Decrypted | |------------|----------|-----------|-----------|| | Python | bibek | ibebk | bibek | | JavaScript | bibek | ibebk | bibek |

Additional Test Cases

Input Encrypted Output Description
hello ehllo Basic word
world owlrd Another word
test etts 4 characters
a a Single character
ab ba Two characters
abc bac Odd length
HELLO EHLLO Uppercase
Hello World! eHll ooWlr!d Mixed case + space
12345 21435 Numbers
!@#$% @!$#% Special characters
cafรฉ acรฉf Accented characters
hello๐Ÿ˜€world ehll๐Ÿ˜€oowlrd With emoji
ใ“ใ‚“ใซใกใฏ ใ‚“ใ“ใกใซใฏ Japanese
ไฝ ๅฅฝไธ–็•Œ ๅฅฝไฝ ็•Œไธ– Chinese
(empty) (empty) Empty string

๐Ÿ” Edge Cases Handled

Case Behavior
Empty string Returns empty string
Single character Returns same character
Odd-length string Last character stays in place
Numbers Treated as characters, swapped
Uppercase/Lowercase Case preserved (case-sensitive)
Unicode (emoji, etc.) Full Unicode support
Spaces/Punctuation Treated as regular characters

๐Ÿ”„ Alternative Algorithms

If you need different encryption methods, here are alternatives:

1. XOR+Base64 Cipher with Key โญ IMPLEMENTED

  • XOR each byte with a repeating key
  • Encode result in Base64 for safe text representation
  • Pros: Key-based, cross-language compatible, more secure than Caesar
  • Files: xor_encrypt.py, xor_encrypt.js
  • Documentation: See XOR_README.md

Quick Example:

# Python
python -c "from xor_encrypt import xor_encrypt; print(xor_encrypt('hello', 'key'))"
# Output: AwAVBwo=

# JavaScript
node -e "const {xorEncrypt} = require('./xor_encrypt.js'); console.log(xorEncrypt('hello', 'key'));"
# Output: AwAVBwo=

2. Caesar Cipher with Fixed Shift

  • Shift each character by a fixed number (e.g., +3)
  • a โ†’ d, b โ†’ e, etc.
  • Pros: Simple, well-known
  • Cons: Easily breakable, doesn't preserve character types

๐Ÿ“Š Cross-Language Validation

To verify identical output across languages:

  1. Python:

    python -c "from encrypt import encrypt; print(encrypt('bibek'))"
    

    Output: ibebk

  2. JavaScript (Node.js):

    node -e "const {encrypt} = require('./encrypt.js'); console.log(encrypt('bibek'))"
    

    Output: ibebk

Both should produce exactly the same output.


๐Ÿ” Using a Seed (Custom Value)

You can pass an optional numeric seed to both encrypt and decrypt to change the transformation deterministically. The implementations rotate the string by seed % len before (encrypt) / after (decrypt) swapping pairs.

Python example:

python -c "from encrypt import encrypt, decrypt; print(encrypt('bibek', 2)); print(decrypt('keibb', 2))"

Node.js example:

node -e "const {encrypt, decrypt} = require('./encrypt.js'); console.log(encrypt('bibek', 2)); console.log(decrypt('keibb', 2));"

Both commands will output the same encrypted/decrypted results when using the same seed.


๐Ÿ› ๏ธ Requirements

Python

  • Python 3.6+ (no external dependencies)

JavaScript

  • Node.js 12+ (for CLI usage)
  • Any modern browser (for web usage)

๐Ÿ“ Notes

  • โš ๏ธ Security Warning:
    • Adjacent Swap & XOR+Base64 are NOT suitable for real-world encryption
    • These are educational/demonstration implementations only
    • For Real Security: Use AES-256-GCM (included in this project!)
  • Character Encoding: All implementations use UTF-8/Unicode for international character support
  • Performance: O(n) time complexity for all methods
  • Cross-Platform: All methods work identically across Python, JavaScript, and browsers

๐Ÿ“„ License

This is an educational project demonstrating encryption concepts from simple to production-grade. Feel free to use and modify as needed.


๐Ÿค Contributing

Contributions welcome! To add support for another language:

  1. Implement the encryption logic following existing patterns
  2. Ensure all test cases pass
  3. Verify output matches existing implementations exactly
  4. Add appropriate documentation

๐ŸŒŸ Features Highlights

  • ๐ŸŽจ Beautiful Web Interface - Modern, responsive design
  • ๐Ÿ“‹ Copy to Clipboard - One-click result copying
  • ๐Ÿ”„ Cross-Language - Python โ†” JavaScript compatibility
  • ๐Ÿงช Comprehensive Tests - 34+ test cases across all methods
  • ๐Ÿ“š Detailed Docs - Complete guides for each method
  • ๐Ÿ›ก๏ธ Production Ready - AES-256 for real security
  • ๐Ÿ“ฑ Mobile Friendly - Responsive tables and layouts
  • ๐ŸŽ“ Educational - Learn from simple to advanced encryption

๐Ÿ”— Quick Links


๐Ÿ™ Acknowledgments

  • AES-256-GCM implementation uses industry-standard cryptographic libraries
  • All algorithms are well-documented and tested
  • UI inspired by modern web design principles

๐Ÿ“ž Support & Issues

If you find any issues:

  • Verify string encoding (UTF-8)
  • Check character iteration order
  • Ensure proper dependency installation
  • Review test outputs for cross-language compatibility

For AES-256 issues:

  • Ensure cryptography library is installed (Python)
  • Verify Web Crypto API support (Browser)
  • Check password/key correctness

Built with โค๏ธ for learning and production use

Happy encrypting! ๐Ÿ”


๐Ÿ“Š Stats

  • 3 Encryption Methods: Simple โ†’ Moderate โ†’ Production
  • 6 Core Files: Python & JavaScript for each method
  • 4 HTML Demos: Interactive web interfaces
  • 34+ Tests: Comprehensive test coverage
  • 6 Documentation Files: Detailed guides
  • 100% Cross-Language Compatible: Verified identical outputs

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

biencrypt-1.0.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

biencrypt-1.0.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file biencrypt-1.0.0.tar.gz.

File metadata

  • Download URL: biencrypt-1.0.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for biencrypt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 40729274fee23cc06939fb86631c8bf5afe9af78ae5800c197fcc467c75bacf4
MD5 f48a72687502516e0e244e24fac8d6f9
BLAKE2b-256 03edd16616d245fe7265d2d6c14e355633a941bbf62e704610d7701e13ffd6e7

See more details on using hashes here.

File details

Details for the file biencrypt-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: biencrypt-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for biencrypt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ebb717a4f408082b44aa5243c769ae353c2a98b227c4e5dc0183a084152188f
MD5 dfb3c74a16955101e4d8295d68ebdb7d
BLAKE2b-256 7d069cb46e558fe8b1a078912f03b012ef7535c3a98048e283396cd5d485f744

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