{"id":20710827,"url":"https://github.com/gabrielagodek/rsa-encryption","last_synced_at":"2025-06-20T10:34:13.960Z","repository":{"id":208499519,"uuid":"718707600","full_name":"GabrielaGodek/RSA-encryption","owner":"GabrielaGodek","description":" This script provides functionality for encrypting and decrypting text using a basic implementation of the RSA algorithm. The RSA algorithm is a widely used public-key cryptosystem that relies on the mathematical properties of large prime numbers.","archived":false,"fork":false,"pushed_at":"2023-12-09T07:41:30.000Z","size":286,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-08T08:03:57.984Z","etag":null,"topics":["matplotlib","python3","rsa-algorithm","rsa-cryptography"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GabrielaGodek.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,"zenodo":null}},"created_at":"2023-11-14T16:29:43.000Z","updated_at":"2023-11-21T19:28:26.000Z","dependencies_parsed_at":"2023-12-09T08:43:58.558Z","dependency_job_id":null,"html_url":"https://github.com/GabrielaGodek/RSA-encryption","commit_stats":null,"previous_names":["gabrielagodek/rsa-encryption"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GabrielaGodek/RSA-encryption","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielaGodek%2FRSA-encryption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielaGodek%2FRSA-encryption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielaGodek%2FRSA-encryption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielaGodek%2FRSA-encryption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GabrielaGodek","download_url":"https://codeload.github.com/GabrielaGodek/RSA-encryption/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielaGodek%2FRSA-encryption/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260927232,"owners_count":23083982,"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":["matplotlib","python3","rsa-algorithm","rsa-cryptography"],"created_at":"2024-11-17T02:13:18.014Z","updated_at":"2025-06-20T10:34:08.941Z","avatar_url":"https://github.com/GabrielaGodek.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RSA Algorithm\n\n## Overview\n`generate_keys.py` generates RSA public and private keys and saves them to separate files. It includes functions for checking prime numbers, finding the greatest common divisor using the Euclidean algorithm, and calculating the modular inverse.\n`RSA.py` script provides functionality for encrypting and decrypting text using a basic implementation of the RSA algorithm. The RSA algorithm is a widely used public-key cryptosystem that relies on the mathematical properties of large prime numbers.\n\n## Essential functions\n\n### `euclidean(a, b)`\nCalculates the greatest common divisor of two numbers `a` and `b` using the Euclidean algorithm.\n\n```Python\ndef euclidean(a, b): \n    while b != 0:\n        a, b = b, a % b\n    return a\n```\n\n### `modulo_inverse(a, m)`\nFinds the modular inverse of `a` modulo `m`.\n```math\nx \\equiv a^{-1} \\pmod{m}\n```\n\n```Python\ndef modulo_inverse(a, m):\n    m0, x0, x1 = m, 0, 1\n    while a \u003e 1:\n        q = a // m\n        m, a = a % m, m\n        x0, x1 = x1 - q * x0, x0\n    return x1 + m0 if x1 \u003c 0 else x1\n \n```\n\n### `encrypt(encrypted_text_path, plaintext_path)`\n\nThis function reads the public key from the 'public.key' file, reads the plaintext from the specified file and converts each character to its ASCII code. The most crucial part is line which raises to the power of the public key (e) with modulo (n).\u003cbr\u003e\n```math\nc \\equiv m^e \\pmod{n} \n```\nThen saves the encrypted values to a file. \n\n```Python\nfor char in formatted_plaintext:\n          encrypted_text.append(pow(int(char), public_key[0], public_key[1]))\n```\n\n### `decrypt(encrypted_text_path, decrypted_text_path)`\n\nThis function reads the private key from the 'private.key' file, reads the encrypted text from the specified file, decrypts each value using the private key using , and then saves the decrypted text to a file.\n```math\nm \\equiv c^d \\pmod{n}\n```\n### `plot_encrypted_text(encrypted_text, key)`\n\n- **Input**: \n    - `encrypted_text` - List of encrypted values.\n    - `key` - List containing two integers representing the public key.\n\nThis function generates a histogram of the encrypted values. It also adds vertical dashed lines at positions corresponding to the public key values 'e' and 'n'. The resulting histogram is saved as 'public/histogram.png'.\n\n## Usage\n\nThe script can be run as a standalone program. It encrypts the text from 'text.txt', saves the encrypted values to 'text.enc', then decrypts the values from 'text.enc' and saves the decrypted text to 'text.dec'.\n\n```python\nif __name__ == '__main__':\n     encrypted_text_path = 'src/texts/text.enc'\n     decrypted_text_path = 'src/texts/text.dec'\n     plaintext_path = 'src/texts/text.txt'\n\n     encrypt(encrypted_text_path, plaintext_path)\n     decrypt(encrypted_text_path, decrypted_text_path)\n```\n\n## Dependencies\n- `matplotlib`: This library is used for plotting the histogram.\n\n\n## Histogram\n![Histogram](public/histogram.png)\n\n### Authors\n\nGabriela Godek\n\n### License\n\nThis project is available for use under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielagodek%2Frsa-encryption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrielagodek%2Frsa-encryption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielagodek%2Frsa-encryption/lists"}