NOCF : Encryption and Decryption Service
'Notes on a conditional form(N.O.C.F)'은 The 1975 앨범 제목이다.
🕊️ 만든이유
'릴리슈슈의 모든 것'에서 릴리어를 보고 멋지다고 생각했다.
나무위키에서 누가 릴리어 번역 프로그램을 만들어놓은 것을 봤던 것 같다.
마침 나도 기록은 하고있는데, 다른 사람이 읽지는 못했으면해서 그런 암호화 프로그램을 만들었다.
📢 Project 설명
📝 Notes on a conditional form
N.O.C.F is an easy and fun web application for encrypting and decrypting text. This site helps users keep their text confidential and communicate securely with others.
Key Features:
Text Encryption: Encrypt your input text using the chosen encryption algorithm. The encrypted text can be safely stored or shared.
Text Decryption: Restore the original text from the encrypted text. The key or algorithm used during encryption is required.
Secret Notes: Encrypt personal notes to keep them secure.
Use Cases:
Secret Messages: Send confidential messages to friends or family.
Protect Personal Notes: Encrypt important personal notes for safe storage.
💥 Site Demo
💅🏻 Tech Stack
Flask(Python), PostgreSQL, React(Javascript), Docker
Time : 4hours
🔑 Logic
Custom Encryption and Decryption System
1. Introduction
This report presents an analysis of a custom encryption and decryption system implemented in Python. The system utilizes a combination of substitution ciphers, base64 encoding, and character shifting to secure text data. The code is designed to handle both ASCII and Korean characters, providing a versatile and culturally relevant encryption solution.
2. Overview of Components
The system is composed of several key components:
Substitution Table Generation and Management:
Generates a random substitution table mapping characters to shuffled counterparts.
Saves and loads the substitution table from a file.
Custom Encryption Algorithm:
Encrypts text by substituting characters, applying a shift based on the number of lines, reversing the text, and finally encoding it with base64.
Custom Decryption Algorithm:
Reverses the encryption process by decoding the base64, reversing the text, and then performing reverse substitution and shifting to recover the original message.
3. Detailed Code Analysis
3.1. Substitution Table Management
3.1.1. generate_substitution_table()
This function generates a substitution table for character substitution. It considers both ASCII printable characters (from space to tilde) and Korean characters (from ‘가’ to ‘힣’).
Steps:
Character Collection: Collects all ASCII printable characters and Korean characters.
Shuffling: Shuffles these characters randomly to create a substitution mapping.
Mapping: Maps each character to a randomly chosen substitute character.
3.1.2. reverse_substitution_table(substitution_table)
This function creates a reverse mapping of the substitution table to facilitate decryption.
Purpose: Ensures that each substituted character can be correctly mapped back to its original form during decryption.
3.1.3. save_substitution_table(substitution_table, filename='substitution_table.pkl')
and load_substitution_table(filename='substitution_table.pkl')
These functions handle the saving and loading of the substitution table using the pickle
module.
Purpose:
Save Function: Serializes the substitution table and saves it to a file.
Load Function: Deserializes and loads the table from the file if it exists, allowing for persistent storage of the table.
3.2. Custom Encryption Algorithm
3.2.1. calculate_shift(text)
This function determines the shift value used in the encryption process.
Calculation: The shift is calculated based on the number of lines in the text, using the formula
shift = text.count('\n') + 1
. This adds an extra level of dynamic shifting based on the structure of the input text.
3.2.2. custom_encrypt(text, substitution_table)
This is the core encryption function.
Process:
Shift Calculation: Determines the shift value from the input text.
Character Substitution and Shifting: For each character in the text:
Applies the shift by adjusting the character’s Unicode value.
Substitutes the shifted character using the substitution table.
Reversal: Reverses the entire encrypted text to add complexity.
Base64 Encoding: Encodes the reversed text into base64 to ensure safe transmission and storage.
Output: The final encrypted text is a base64-encoded string.
3.3. Custom Decryption Algorithm
3.3.1. custom_decrypt(text, substitution_table)
This function reverses the encryption process to retrieve the original text.
Process:
Base64 Decoding: Decodes the base64-encoded text to retrieve the reversed encrypted string.
Reversal: Reverses the string back to its original order before reversal.
Reverse Substitution and Shifting: For each character:
Applies the reverse substitution using the reverse substitution table.
Adjusts the character’s Unicode value by reversing the shift.
Output: The final output is the original, decrypted text.
4. Security and Considerations
4.1. Strengths
Multiple Layers of Security: The system combines multiple encryption techniques (substitution, shifting, reversal, base64 encoding), making it more resistant to simple attacks.
Handling of Multilingual Characters: The inclusion of Korean characters makes the encryption scheme culturally relevant and capable of handling diverse data.
4.2. Potential Weaknesses
Predictability of Shifting Mechanism: The shift is based on the number of lines, which could be predictable in some cases, potentially reducing security.
Substitution Table Persistence: If the substitution table is compromised, the entire encryption system could be vulnerable, highlighting the need for secure storage.
4.3. Usage Considerations
Performance: For large texts, the multiple layers of encryption could introduce significant computational overhead.
Scalability: The current system is well-suited for small to medium-sized text blocks, but scalability could be an issue for larger datasets or real-time applications.
5. Conclusion
The custom encryption and decryption system presented here offers a unique and multi-faceted approach to securing text data. While it effectively combines several encryption techniques, ensuring the security of the substitution table and considering potential optimizations for larger datasets would be essential for its broader application. This system is particularly useful for applications requiring the encryption of texts containing both ASCII and Korean characters, making it versatile in a globalized context.
🔐 Update
substitution table backup
admin용 json 파일 backup 및 restore 기능 추가
encoding update
암호화 키 관리: 대체 테이블을 파일에 저장하는 대신, 암호화된 키를 사용하여 보다 안전하게 대체 테이블을 관리합니다.
시프트 값 보호: 시프트 값을 암호화하거나 복잡하게 계산하여 예측 가능성을 줄입니다.
입력 검증: 입력 텍스트를 검증하여 악의적인 코드 주입을 방지합니다.
로그 및 모니터링: 로그를 추가하여 암호화 및 복호화 작업을 기록합니다.
LargeBinary with pickle
Last updated