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.
- π 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
- Python 3.8+
- Django 3.2+
- Django REST Framework 3.12+
- 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')),
]GET /api/health/
{
"status": "ok"
}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"
}POST /api/decrypt/
{
"encrypted_text": "109a507%12c114a507%12c..."
}Response:
{
"success": true,
"encrypted_text": "109a507%12c114a507%12c...",
"decrypted_text": "Hello World!",
"message": "Text decrypted successfully"
}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
}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"
}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
- Basic (n): Random salt between 50-100
- Medium (m): Random salt between 500-1000
- Advanced (a): Random salt between 5000-10000
Each character is encrypted to:
[encrypted_number][random_letter][level]%[original_text_length][random_letter]
Example: 109a507%12c
The API returns appropriate HTTP status codes:
200 OK: Success400 Bad Request: Invalid input500 Internal Server Error: Server-side error
Error responses include detailed messages:
{
"error": "Text is required and must be a string"
}- 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
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']# 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..."}'// 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));Run Django tests:
python manage.py test chaocrypt- Extend the character map in
normal_case_map - Add new encryption levels in the
_encrypt_textmethod - Create new endpoints by extending
APIView
- 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
- Fork the repository
- Create a feature branch
- Make changes with tests
- Submit a pull request
MIT License - See LICENSE file for details.
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