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
- New to this project? โ QUICKSTART.md
- Adjacent Swap details โ ALGORITHM.md
- XOR+Base64 guide โ XOR_README.md
- AES-256 guide โ AES_README.md
- Compare all methods โ COMPARISON.md
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:
- Open
index.htmlin your browser - Choose your encryption method
- 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)
cryptographylibrary 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:
-
Python:
python -c "from encrypt import encrypt; print(encrypt('bibek'))"
Output:
ibebk -
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:
- Implement the encryption logic following existing patterns
- Ensure all test cases pass
- Verify output matches existing implementations exactly
- 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
- ๐ Quick Start Guide
- ๐ Adjacent Swap Algorithm
- ๐ XOR+Base64 Documentation
- ๐ก๏ธ AES-256 Documentation
- โ๏ธ Full Comparison
- ๐ Original Specifications
๐ 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
cryptographylibrary 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40729274fee23cc06939fb86631c8bf5afe9af78ae5800c197fcc467c75bacf4
|
|
| MD5 |
f48a72687502516e0e244e24fac8d6f9
|
|
| BLAKE2b-256 |
03edd16616d245fe7265d2d6c14e355633a941bbf62e704610d7701e13ffd6e7
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ebb717a4f408082b44aa5243c769ae353c2a98b227c4e5dc0183a084152188f
|
|
| MD5 |
dfb3c74a16955101e4d8295d68ebdb7d
|
|
| BLAKE2b-256 |
7d069cb46e558fe8b1a078912f03b012ef7535c3a98048e283396cd5d485f744
|