{"id":26867649,"url":"https://github.com/asfhtgkdavid/nal-encryption","last_synced_at":"2025-05-07T02:05:46.580Z","repository":{"id":270617259,"uuid":"910937433","full_name":"AsfhtgkDavid/NAL-Encryption","owner":"AsfhtgkDavid","description":"Lightweight symetric encryption","archived":false,"fork":false,"pushed_at":"2025-04-21T18:39:03.000Z","size":7316,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T02:05:41.936Z","etag":null,"topics":["encryption","encryption-decryption","python","python3","secure","security","security-tools"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/nalenc/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AsfhtgkDavid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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,"zenodo":null}},"created_at":"2025-01-01T20:58:33.000Z","updated_at":"2025-04-19T17:12:04.000Z","dependencies_parsed_at":"2025-01-01T21:32:06.070Z","dependency_job_id":"a66eac08-9e51-464e-82d9-79c0a331f96e","html_url":"https://github.com/AsfhtgkDavid/NAL-Encryption","commit_stats":null,"previous_names":["asfhtgkdavid/nal-encryption"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsfhtgkDavid%2FNAL-Encryption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsfhtgkDavid%2FNAL-Encryption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsfhtgkDavid%2FNAL-Encryption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsfhtgkDavid%2FNAL-Encryption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AsfhtgkDavid","download_url":"https://codeload.github.com/AsfhtgkDavid/NAL-Encryption/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252798853,"owners_count":21805887,"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","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":["encryption","encryption-decryption","python","python3","secure","security","security-tools"],"created_at":"2025-03-31T05:17:51.024Z","updated_at":"2025-05-07T02:05:46.571Z","avatar_url":"https://github.com/AsfhtgkDavid.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NALEnc - Python Encryption Library\n\n**NALEnc** is a lightweight Python encryption library designed for securely encrypting and decrypting text and binary data. With an intuitive interface and robust functionality, it is ideal for developers seeking a straightforward yet effective encryption solution.\n\n---\n\n## 🚀 Features\n\n- **Flexible Input:** Encrypt and decrypt strings, binary data, or NumPy arrays.\n- **Password Support:** Accepts passwords as strings, bytes, lists of integers (0-255), or NumPy arrays.\n- **Optimized for Performance:** Best suited for messages of size `2046n`, where `n ∈ N`.\n- **Powered by NumPy:** Leverages NumPy for efficient operations.\n- **Command-Line Interface:** Includes a `nalenc` CLI tool for easy file encryption/decryption and key generation directly from your terminal.\n\n---\n\n## 📦 Installation\n\nInstall the library via pip:\n\n```bash\npip install nalenc\n```\n\n---\n\n## 📝 Usage\n\n### 🔗 Importing the Library\n\n```python\nimport nalenc\nimport numpy as np\n```\n\n### 🔑 Creating an Instance of NALEnc\n\nTo use the library, create an instance of the `NALEnc` class with a password. The password can be:\n\n- A string\n- A byte sequence\n- An iterable of integers (each in the range `0-255`)\n- A NumPy array of integers (dtype must be `np.uint8`)\n\nExample:\n\n```python\n# Generate a password as a NumPy array\npassword = np.random.randint(0, 256, size=512, dtype=np.uint8)\nnal = nalenc.NALEnc(password)\n```\n\n### 🔒 Encrypting Data\n\nUse the `encrypt` method to encrypt a message. Supported input types:\n\n- **String**\n- **Byte sequence**\n- **Iterable of integers** (0-255)\n- **NumPy array** (dtype: `np.uint8`)\n\nExample:\n\n```python\n# Encrypt a string\nencrypted = nal.encrypt(\"Hello, World!\")\n\n# Encrypt binary data\nbinary_data = b\"\\x89PNG\\r\\n\\x1a\\n\"\nencrypted_binary = nal.encrypt(binary_data)\n\n# Encrypt a NumPy array\narray_data = np.array([1, 2, 3, 4, 5], dtype=np.uint8)\nencrypted_array = nal.encrypt(array_data)\n```\n\n### 🔓 Decrypting Data\n\nUse the `decrypt` method to decrypt an encrypted message.\n\nExample:\n\n```python\n# Decrypt the encrypted string\ndecrypted = nal.decrypt(encrypted)  # Returns a list of integers\n\n# Decrypt binary data\ndecrypted_binary = nal.decrypt(encrypted_binary)\n\n# Decrypt a NumPy array\ndecrypted_array = nal.decrypt(encrypted_array)\n```\n\n## 💻 Command-Line Interface (CLI) Usage\n\nThe `nalenc` command-line tool allows for quick encryption, decryption, and key generation without writing Python code.\n\n### Verify Installation\n\n```bash\nnalenc --version\n```\n\n### CLI Commands\n\nThe tool provides three main commands: `generate-key`, `encrypt`, and `decrypt`.\n\n#### 1. Generate Key (`generate-key`)\n\nCreates a new 512-byte encryption key.\n\n```bash\nnalenc generate-key [OPTIONS]\n```\n\n**Options:**\n\n*   `-o, --output FILE`: Output file for the key (default: stdout).\n*   `-a, --ascii`: Output key in ASCII format (Base64 with headers `----BEGIN NAL KEY----` / `----END NAL KEY----`).\n\n**Examples:**\n\n*   Generate a binary key file:\n    ```bash\n    nalenc generate-key \u003e mykey.bin\n    ```\n*   Generate an ASCII key file:\n    ```bash\n    nalenc generate-key -o mykey.key -a\n    ```\n\n#### 2. Encrypt Data (`encrypt`)\n\nEncrypts data from a file or stdin using a specified key.\n\n```bash\nnalenc encrypt -k KEY_FILE [OPTIONS] [INPUT_FILE]\n```\n\n**Arguments:**\n\n*   `INPUT_FILE`: Input file to encrypt (default: stdin).\n\n**Options:**\n\n*   `-k, --key FILE`: **(Required)** Encryption key file (binary or ASCII).\n*   `-o, --output FILE`: Output file for encrypted data (default: stdout).\n*   `-a, --ascii`: Output result in ASCII format (Base64 with headers `----BEGIN NAL MESSAGE----` / `----END NAL MESSAGE----`).\n\n#### 3. Decrypt Data (`decrypt`)\n\nDecrypts data from a file or stdin using a specified key.\n\n```bash\nnalenc decrypt -k KEY_FILE [OPTIONS] [INPUT_FILE]\n```\n\n**Arguments:**\n\n*   `INPUT_FILE`: Input file to decrypt (binary or ASCII, default: stdin).\n\n**Options:**\n\n*   `-k, --key FILE`: **(Required)** Encryption key file (binary or ASCII).\n*   `-o, --output FILE`: Output file for decrypted data (default: stdout).\n*   `-a, --ascii`: Output result in ASCII format. (Note: Only affects output format; input format is auto-detected if it uses the standard headers).\n\n### 📂 Working with Binary Files\n\nNALEnc supports encrypting and decrypting binary files. Read the file as binary data, process it, and save the result. Cast the encrypted data to `bytes` before writing to a file.\n\nExample:\n\n```python\n# Encrypt a binary file\nwith open(\"input.bin\", \"rb\") as f:\n    data = f.read()\n\nencrypted_data = nal.encrypt(data)\n\nwith open(\"output.enc\", \"wb\") as f:\n    f.write(bytes(encrypted_data))\n\n# Decrypt the binary file\nwith open(\"output.enc\", \"rb\") as f:\n    encrypted_data = f.read()\n\ndecrypted_data = nal.decrypt(encrypted_data)\n\nwith open(\"decrypted.bin\", \"wb\") as f:\n    f.write(bytes(decrypted_data))\n```\n\n---\n\n## 📈 Optimal Message Size\n\nFor best performance, ensure message sizes are `2048n - 2`, where `n` is a positive integer. This helps maximize efficiency during encryption and decryption.\n\n---\n\n## 📚 API Reference\n\n### Class: `NALEnc`\n\n#### Constructor\n\n```python\nNALEnc(password: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])\n```\n\n- **password**: The encryption password. Acceptable types:\n  - String\n  - Byte sequence\n  - Iterable of integers (0-255)\n  - NumPy array (`np.types.NDArray[np.uint8]`)\n\n#### Methods\n\n##### `encrypt(msg: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])`\n\nEncrypts the given message.\n\n- **msg**: The message to encrypt. Input types:\n  - String\n  - Byte sequence\n  - Iterable of integers (0-255)\n  - NumPy array (`np.types.NDArray[np.uint8]`)\n- **Returns**: The encrypted message as a list of integers.\n\n##### `decrypt(msg: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])`\n\nDecrypts the given encrypted message.\n\n- **msg**: The encrypted message. Input types:\n  - String\n  - Byte sequence\n  - Iterable of integers (0-255)\n  - NumPy array (`np.types.NDArray[np.uint8]`)\n- **Returns**: The decrypted message as a list of integers.\n\n---\n\n## 💡 Example Code\n\n```python\nimport nalenc\nimport numpy as np\n\n# Generate a random password\npassword = np.random.randint(0, 256, size=512, dtype=np.uint8)\n\n# Create an instance of NALEnc\nnal = nalenc.NALEnc(password)\n\n# Encrypt a message\nmessage = \"Encrypt this message!\"\nencrypted = nal.encrypt(message)\n\n# Decrypt the message\ndecrypted = nal.decrypt(encrypted)\n\nprint(\"Original:\", message)\nprint(\"Encrypted:\", bytes(encrypted))  # Cast to bytes for readability\nprint(\"Decrypted:\", bytes(decrypted))\n```\n\n---\n\n## 📜 License\n\nThis library is licensed under the LGPL License. See the COPYING and COPYING.LESSER files for more information.\n\n---\n\nFor questions, feedback, or contributions, feel free to open an issue on the [GitHub repository](https://github.com/AsfhtgkDavid/NAL-Encryption).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasfhtgkdavid%2Fnal-encryption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasfhtgkdavid%2Fnal-encryption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasfhtgkdavid%2Fnal-encryption/lists"}