Chaocrypt API v3
A Django REST Framework API for the Chaocrypt v3 encryption algorithm. This service provides endpoints for encrypting and decrypting text using a custom cipher algorithm with multiple security levels.
Features
- ๐ Multi-level encryption: Basic, Medium, and Advanced security levels
- ๐ Bidirectional conversion: Encrypt plaintext to ciphertext and decrypt back
- ๐ฆ Batch processing: Encrypt multiple texts in a single request
- ๐ก๏ธ Production-ready: Error handling, validation, and logging
- ๐ Health monitoring: Built-in health check endpoint
- ๐ Cipher information: Detailed information about the encryption algorithm
Installation
Prerequisites
- Python 3.8+
- Django 3.2+
- Django REST Framework 3.12+
Setup
- Clone and install dependencies:
pip install django djangorestframework
- Add to Django settings:
INSTALLED_APPS = [
...,
'rest_framework',
'chaocrypt', # Your app name
]
- Configure URLs in your project's
urls.py:
from django.urls import path, include
urlpatterns = [
...,
path('api/', include('chaocrypt.urls')),
]
API Endpoints
1. Health Check
GET /api/health/
{
"status": "ok"
}
2. Encrypt Text
POST /api/encrypt/
{
"text": "Hello World!",
"level": "medium" // "basic", "medium", or "advanced"
}
Response:
{
"success": true,
"original_text": "Hello World!",
"encrypted_text": "109a507%12c114a507%12c...",
"level": "m",
"message": "Text encrypted successfully"
}
3. Decrypt Text
POST /api/decrypt/
{
"encrypted_text": "109a507%12c114a507%12c..."
}
Response:
{
"success": true,
"encrypted_text": "109a507%12c114a507%12c...",
"decrypted_text": "Hello World!",
"message": "Text decrypted successfully"
}
4. Batch Encrypt
POST /api/batch-encrypt/
{
"texts": ["Hello", "World", "123"],
"level": "basic"
}
Response:
{
"success": true,
"level": "n",
"results": [
{
"original_text": "Hello",
"encrypted_text": "102a65%5c...",
"error": null
},
...
],
"total": 3
}
5. Cipher Information
GET /api/info/
{
"cipher_name": "Chaocrypt v3",
"character_set_size": 70,
"supported_characters": ["a", "b", "c", ...],
"encryption_levels": {
"n": "Normal (50-100)",
"m": "Medium (500-1000)",
"a": "Advanced (5000-10000)"
},
"format": "Each character becomes: number + random_letter + level%original_length + random_letter"
}
Encryption Algorithm
Overview
Chaocrypt v3 uses a substitution cipher with added salt and randomization:
- Character Mapping: Each character maps to a unique number (101-1069)
- Salt Addition: Adds salt based on text length and encryption level
- Randomization: Includes random letters and encryption level in output
Encryption Levels
- Basic (n): Random salt between 50-100
- Medium (m): Random salt between 500-1000
- Advanced (a): Random salt between 5000-10000
Output Format
Each character is encrypted to:
[encrypted_number][random_letter][level]%[original_text_length][random_letter]
Example: 109a507%12c
Error Handling
The API returns appropriate HTTP status codes:
200 OK: Success
400 Bad Request: Invalid input
500 Internal Server Error: Server-side error
Error responses include detailed messages:
{
"error": "Text is required and must be a string"
}
Security Considerations
- Not for Production Security: This is a custom cipher for educational/demo purposes
- Randomization: Each encryption uses random salt values
- Input Validation: All inputs are validated and sanitized
- Error Messages: Generic error messages to avoid information leakage
Usage Examples
Python
import requests
# Encrypt
response = requests.post('http://localhost:8000/api/encrypt/',
json={'text': 'Secret Message', 'level': 'advanced'})
encrypted = response.json()['encrypted_text']
# Decrypt
response = requests.post('http://localhost:8000/api/decrypt/',
json={'encrypted_text': encrypted})
decrypted = response.json()['decrypted_text']
cURL
# Encrypt
curl -X POST http://localhost:8000/api/encrypt/ \
-H "Content-Type: application/json" \
-d '{"text": "Hello World", "level": "medium"}'
# Decrypt
curl -X POST http://localhost:8000/api/decrypt/ \
-H "Content-Type: application/json" \
-d '{"encrypted_text": "109a507%12c..."}'
JavaScript
// Encrypt
fetch('/api/encrypt/', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: 'Hello', level: 'basic'})
})
.then(response => response.json())
.then(data => console.log(data.encrypted_text));
Testing
Run Django tests:
python manage.py test chaocrypt
Development
Adding New Features
- Extend the character map in
normal_case_map
- Add new encryption levels in the
_encrypt_text method
- Create new endpoints by extending
APIView
Known Limitations
- Duplicate characters in original map were deduplicated (kept first occurrence)
- Maximum text length is limited by performance considerations
- Special characters support is comprehensive but not exhaustive
Contributing
- Fork the repository
- Create a feature branch
- Make changes with tests
- Submit a pull request
License
MIT License - See LICENSE file for details.
Support
For issues and questions:
- Check the API documentation
- Review error messages in responses
- Ensure correct input format
- Check server logs for detailed errors
This idea is meant to slow down bruteforce attack and to render data useless in case of data breach, you will need your own algorithm and this is experimental and educational purpose.
Made by Conscience Ekhomwandolor with tap_drf