{"id":27072995,"url":"https://github.com/yo525/sme","last_synced_at":"2025-09-10T04:10:11.226Z","repository":{"id":284772733,"uuid":"956008011","full_name":"yo525/SME","owner":"yo525","description":"SME256 Encryption Library is a Python package that implements the 256 Scrambled-Matrix-Encryption (SME256) algorithm","archived":false,"fork":false,"pushed_at":"2025-03-27T15:09:33.000Z","size":142,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T23:34:23.198Z","etag":null,"topics":["algorithm","benchmark","cryptography","decrypt","decryption-algorithm","decryption-library","encrypt","encryption","encryption-algorithms","encryption-decryption","encryption-library","library","matrix","matrix-calculations","user-friendly","user-friendly-tool"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yo525.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-27T14:50:52.000Z","updated_at":"2025-03-28T14:19:31.000Z","dependencies_parsed_at":"2025-03-27T16:34:47.854Z","dependency_job_id":null,"html_url":"https://github.com/yo525/SME","commit_stats":null,"previous_names":["yo525/sme"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yo525/SME","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yo525%2FSME","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yo525%2FSME/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yo525%2FSME/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yo525%2FSME/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yo525","download_url":"https://codeload.github.com/yo525/SME/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yo525%2FSME/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274411317,"owners_count":25280108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","benchmark","cryptography","decrypt","decryption-algorithm","decryption-library","encrypt","encryption","encryption-algorithms","encryption-decryption","encryption-library","library","matrix","matrix-calculations","user-friendly","user-friendly-tool"],"created_at":"2025-04-05T23:34:25.782Z","updated_at":"2025-09-10T04:10:11.197Z","avatar_url":"https://github.com/yo525.png","language":"Python","readme":"﻿\n# SME256 Encryption Library\n![Apache-2.0 License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)     ![Python Version](https://img.shields.io/badge/python-3.10%2B-green.svg)\n![none](https://img.shields.io/github/languages/code-size/yo525/SME)\n\nThe **SME256 Encryption Library** is a Python package that implements the 256 Scrambled-Matrix-Encryption (SME256) algorithm. It provides encryption and decryption functionalities with dynamic matrix transformations.\n\n## Table of Contents\n\n- [Files](#files)\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Basic Encryption/Decryption](#basic-encryptiondecryption)\n  - [Dependent Matrix Encryption/Decryption](#dependent-matrix-encryptiondecryption)\n  - [Step-by-Step Encryption/Decryption (shows each step)](#step-by-step-encryptiondecryption-shows-each-step)\n  - [Performance Benchmarking and matrix integrity checker](#performance-benchmarking-and-matrix-integrity-checker)\n-  [Workflow](#workflow)\n\t- [SME256BF Workflow](#sme256bf-workflow)\n\t- [SME256dBF Workflow](#sme256dbf-workflow)\n-  [Matrix Transformations](#matrix-transformations)\n- [API Reference](#api-reference)\n- [Contributing](#contributing)\n- [License](#license)\n- [Security Disclosure](#security-disclosure)\n- [Roadmap](#roadmap)\n- [Contact](#contact)\n\n## Files\n\n- [SME.py](SME.py) --\u003e Main core of the SME256 Encryption Library\n- [extendSME.py](extendSME.py) --\u003e Extends/adds functions to the SME main core\n\n## Features\n\n-  **Scrambled-Matrix-Encryption (SME256):** A unique encryption algorithm that uses a scrambled matrix for encryption and decryption.\n-  **Rich Console Output:** Utilizes the `rich` library to provide visually appealing and informative console output.\n- **Performance Benchmarking:** Includes methods to benchmark the performance of the encryption algorithm.\n- **Step-by-Step Visualization:** Provides a step-by-step visualization of the encryption and decryption processes.\n- **Multiple Encryption Modes:** \n\t- **SME256:** 256 Scrambled Matrix Encryption.\n\t\t- **SME256BF:** Byte-Flow Encryption. Basic frame encryption function.\n\t\t- **SME256dBF:** Dependent-Byte-Flow Encryption with dynamic matrix updates. Updates the transformation matrix dynamically during encryption and decryption.\n- **Error Handling:** Comprehensive error handling to manage invalid inputs and index errors gracefully.\n- **Matrix Operations:** Advanced matrix operations for row and column rotations, ensuring data integrity.\n\n## Installation\n\n### Prerequisites\n\n- **Python 3.8 or higher**\n- **pip** (Python package installer)\n\n### Steps\n\n1. **Clone the Repository**\n\n   ```bash\n   git clone https://github.com/yo525/SME.git\n   cd SME\n   ```\n\n2. **Install Dependencies** [^1]\n\n   ```bash\n   # This is only necessary if you want to make use of the extendSME version\n   # Use pip or pip3 to install the requirements\n   pip install -r requirements.txt\n   ```\n\n## Usage\n\n### Basic Encryption/Decryption\n\n\n```python\nfrom SME import SME256BF\nfrom  hashlib  import  scrypt\n\n# Calculate the password using a secure key derivation function like scrypt from the hashlib python module\np =  scrypt(password=b'your_secure_password', salt=b'random_generate_phrase', dklen=16, n=2**14, r=8, p=1)\n\n# Initialize the SME256BF object with a password\nsme = SME256BF(password=p)\n\n# Encrypt a plaintext message\nplaintext = \"Hello, World!\"\nciphertext = sme.encrypt(plaintext)\nprint(f\"Ciphertext: {ciphertext}\")\n\n# Decrypt the ciphertext back to plaintext\ndecrypted_text = sme.decrypt(ciphertext)\nprint(f\"Decrypted Text: {decrypted_text}\")\n```\n![](/assets/basic_encryption-decryption.png)\n\n### Dependent Matrix Encryption/Decryption\n\n```python\nfrom SME import SME256dBF\nfrom  hashlib  import  scrypt\n\n# Calculate the password using a secure key derivation function like scrypt from the hashlib python module\np =  scrypt(password=b'your_secure_password', salt=b'random_generate_phrase', dklen=16, n=2**14, r=8, p=1)\n\n# Initialize the SME256dBF object with a password\nsme_dbf = SME256dBF(password=p)\n\n# Encrypt a plaintext message with dynamic matrix transformation\nplaintext = \"Hello, World!\"\nciphertext = sme_dbf.encrypt(plaintext)\nprint(f\"Ciphertext: {ciphertext}\")\n\n# Decrypt the ciphertext back to plaintext with dynamic matrix transformation\ndecrypted_text = sme_dbf.decrypt(ciphertext)\nprint(f\"Decrypted Text: {decrypted_text}\")\n```\n![](/assets/dependent_matrix_encryption-decryption.png)\n\n### Step-by-Step Encryption/Decryption (shows each step) [^2]\n\n```python\n# Only available with the extendSME version\nfrom extendSME import SME256BF\nfrom  hashlib  import  scrypt\n\n# Calculate the password using a secure key derivation function like scrypt from the hashlib python module\np =  scrypt(password=b'your_secure_password', salt=b'random_generate_phrase', dklen=16, n=2**14, r=8, p=1)\n\n# Initialize the SME256BF object with a password\nsme = SME256BF(password=p)\n\n# Encrypt a plaintext message with step-by-step display\nplaintext = \"Hello, World!\"\nciphertext = sme.encrypt_show(plaintext)\nprint(f\"Ciphertext: {ciphertext}\")\n\n# Decrypt the ciphertext back to plaintext with step-by-step display\ndecrypted_text = sme.decrypt_show(ciphertext)\nprint(f\"Decrypted Text: {decrypted_text}\")\n```\n![](/assets/step-by-step_encryption-decryption.png)\n\n### Performance Benchmarking and matrix integrity checker [^3]\n\n```python\n# Only available with the extendSME version\nfrom extendSME import SME256BF\nfrom  hashlib  import  scrypt\n\n# Calculate the password using a secure key derivation function like scrypt from the hashlib python module\np =  scrypt(password=b'your_secure_password', salt=b'random_generate_phrase', dklen=16, n=2**14, r=8, p=1)\n\n# Initialize the SME256BF object with a password\nsme = SME256BF(password=p)\n\n# Benchmark the SME256 algorithm and display the calculate matrix\nsme.check(cycles=1000)\n```\n## Workflow\n\n### SME256BF Workflow\n\nThe `SME256BF` class extends the `SME256` class and implements basic frame encryption functions. Here is a step-by-step breakdown of its workflow:\n\n1.  **Initialization (`__init__` method):**\n    \n    -   Initializes the SME256 object with a password.\n    -   Checks the password length and prints a warning if it's too short.\n    -   Initializes the transformation matrix based on the password.\n\n2.  **Encryption (`encrypt` method):**\n    \n    -   **Step 1:** Convert plaintext to bytes if it is not already.\n    -   **Step 2:** For each byte in the plaintext:\n        -   Map the byte to a value in the transformed matrix (uses the plaintext value as index to get the ciphertext value in the matrix).\n        -   Append the mapped value to the ciphertext.\n    -   **Step 3:** Returns the resulting ciphertext.\n \n3.  **Encryption with Display (`encrypt_show` method):** [^2]\n    \n    - Similar to `encrypt`, but includes a step-by-step display of the encryption process using the `rich` library.\n    -   Pauses between steps for better visualization.\n \n5.  **Decryption (`decrypt` method):**\n    \n    -   **Step 1:** Convert ciphertext to bytes if it is not already.\n    -   **Step 2:** For each byte in the ciphertext:\n        -   Find the index of the byte in the transformed matrix.\n        -   Append the index byte to the plaintext.\n    -   **Step 3:** Returns the resulting plaintext.\n\n\n6.  **Decryption with Display (`decrypt_show` method):** [^2]\n    \n    - Similar to `decrypt`, but includes a step-by-step display of the decryption process using the `rich` library.\n    -   Pauses between steps for better visualization.\n\n### SME256dBF Workflow\n\nThe `SME256dBF` class also extends the `SME256` class but implements an alternative encryption method that updates the transformation matrix dynamically during encryption and decryption. Here is a step-by-step breakdown of its workflow:\n\n1.  **Initialization (`__init__` method):**\n    \n    -   Initializes the SME256 object with a password.\n    -   Checks the password length and prints a warning if it's too short.\n    -   Initializes the transformation matrix based on the password\n\n2.  **Encryption (`encrypt` method):**\n    \n    -   **Step 1:** Convert plaintext to bytes if it is not already.\n    -   **Step 2:** For each byte in the plaintext:\n        -   Map the byte to a value in the transformed matrix (uses the plaintext value as index to get the ciphertext value in the matrix).\n        -   Append the mapped value to the ciphertext.\n        -   Update the matrix based on the XOR of the current matrix value and the plaintext byte.\n    -   **Step 3:** Returns the resulting ciphertext.\n\n3.  **Encryption with Display (`encrypt_show` method):** [^2]\n    \n    - Similar to `encrypt`, but includes a step-by-step display of the encryption process using the `rich` library.\n    -   Pauses between steps for better visualization.\n    -   Dynamically updates the transformation matrix and displays the changes.\n\n\n4.  **Decryption (`decrypt` method):**\n    \n    -   **Step 1:** Convert ciphertext to bytes if it is not already.\n    -   **Step 2:** For each byte in the ciphertext:\n        -   Find the index of the byte in the transformed matrix.\n        -   Append the index byte to the plaintext.\n        -   Update the matrix dynamically based on the XOR of the current matrix value and the plaintext byte.\n    -   **Step 3:** Returns the resulting plaintext.\n\n\n5.  **Decryption with Display (`decrypt_show` method):** [^2]\n\n    - Similar to `decrypt`, but includes a step-by-step display of the decryption process using the `rich` library.\n    -   Pauses between steps for better visualization.\n    -   Dynamically updates the transformation matrix and displays the changes.\n ## Matrix Transformations\n\nThe matrix transformations in the SME256 algorithm are crucial for the encryption and decryption processes. The transformations include:\n\n-   **Initialization:**\n    \n    -   The matrix is initialized with values from 0 to 255.\n-   **Password-Based Transformation:**\n    \n    -   The matrix is scrambled based on the provided password using a series of rotations and scramblings.\n\n### Detailed Transformation Steps\n\n1.  **Rotation of Rows and Columns:**\n    \n    -   Rows and columns of the matrix are rotated based on the XOR of the current matrix value and the password byte.\n    -   This involves shifting elements within rows and columns to create a scrambled matrix.\n2.  **Scrambling Based on Index:**\n    \n    -   The matrix is scrambled using specific patterns based on the index calculated from the XOR operation.\n    -   This involves converting columns to rows and applying even/odd rules to further scramble the matrix.\n3.  **Bringing Values to the Front:**\n    \n    -   Specific values are moved to the front of the matrix based on their index.\n    -   This ensures that the matrix remains dynamic and scrambled throughout the process.\n \n## API Reference\n\n- **SME256 Class:**\n  - `__init__(password: bytes, warnings: bool = True)`\n  - `check`[^3]`(cycles: int = 1000)`\n  - `rotate_column(column_index: int, pos: int) -\u003e list`\n  - `rotate_row(row_index: int, pos: int) -\u003e list`\n  - `rotate_row_column(n: int) -\u003e None`\n  - `bring_front(value_index: int) -\u003e None`\n  - `column_to_row_even(column_index: int, row_index: int) -\u003e list`\n  - `column_to_row_uneven(column_index: int, row_index: int) -\u003e list`\n  - `column_select_scrambler_uneven(index: int) -\u003e None`\n  - `column_select_scrambler_even(index: int) -\u003e None`\n  - `imprimir`[^2]`(val: list = [], subtitule: str = None, color: str = 'blue', matriz: list = None) -\u003e None`\n  - `print_matrix`[^2]`(self) -\u003e None`\n  - `calculate_table_from_values(values: bytes = None) -\u003e None`\n  - `calculate_table_from_values_show`[^2]`(interval: int | float = 0.01, eliminar: bool = False, values: bytes = None) -\u003e None`\n\n- **SME256BF Class (extends SME256):**\n  - `encrypt(plaintext: bytes | str) -\u003e bytes`\n  - `encrypt_show`[^2]`(plaintext: bytes | str, interval: int = 0.001) -\u003e bytes`\n  - `decrypt(ciphertext: bytes | str) -\u003e bytes`\n  - `decrypt_show`[^2]`(ciphertext: bytes | str, interval: int = 0.001) -\u003e bytes`\n\n- **SME256dBF Class (extends SME256):**\n  - `encrypt(plaintext: bytes | str) -\u003e bytes`\n  - `encrypt_show`[^2]`(plaintext: bytes | str, interval: int = 0.001) -\u003e bytes`\n  - `decrypt(ciphertext: bytes | str) -\u003e bytes`\n  - `decrypt_show`[^2]`(ciphertext: bytes | str, interval: int = 0.001) -\u003e bytes`\n\n\n## Contributing\n\nContributions are welcome! Please follow the guidelines below to contribute to the project:\n\n1. **Fork the Repository**\n2. **Create Your Feature Branch (`git checkout -b feature/AmazingFeature`)** \n3. **Commit Your Changes (`git commit -m 'Add some AmazingFeature'`)** \n4. **Push to the Branch (`git push origin feature/AmazingFeature`)** \n5. **Open a Pull Request**\n\n## License\n\nThis project is licensed under the **Apache-2.0 License**. For more details, see the [LICENSE](LICENSE) file.\n\n## Security Disclosure\n\n**Important**: The SME256 encryption algorithm is a custom implementation and has not undergone rigorous security analysis. While it incorporates various encryption techniques and dynamic updates, it is recommended to use it with caution and not for critical applications where security is paramount. Always evaluate encryption libraries based on their security audits and peer reviews before deploying them in production environments.\n\n## Roadmap\n\n- [ ] **Performance Enhancements**: Optimize matrix transformations and encryption/decryption processes for faster performance.\n- [ ] **Additional Modes**: Introduce new encryption modes with different matrix transformation techniques.\n- [ ] **Documentation/Whitepaper:** Improved documentation and created a white paper to explain the encryption/decryption algorithm step by step.\n- [ ] **Correction of the SME256dBF:** SME256dBF has a vulnerability that allows an attacker to obtain the password of an encrypted message if both the plaintext and ciphertext are available. This can later be used to compromise other information if it has been encrypted with the same password. This is a critical vulnerability that must be addressed.\n\n## Contact\n\n- **Author:** yo525\n- **Email:** [yo525@proton.me](mailto:yo525@proton.me)\n-   **GitHub:** [yo525](https://github.com/yo525)\n\nFeel free to reach out for any questions or feedback!\n\n[^1]: *Not required for the check function.*\n[^2]: *Only available with the extendSME version. Dependencies installation necessary, dependencies required.*\n[^3]: *Only available with the extendSME version. Dependencies installation not necessary, dependencies not required.*\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyo525%2Fsme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyo525%2Fsme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyo525%2Fsme/lists"}