From ab66a7a47472f147594d47902d06e6eaa3b36244 Mon Sep 17 00:00:00 2001 From: obiwan69 <42412299+obiwan69@users.noreply.github.com> Date: Tue, 15 Oct 2019 22:45:32 +0530 Subject: [PATCH] Create key-pair-generator.py Create description.md Create requirements.txt Rename description.md to README.md Update requirements.txt Update README.md --- README.md | 1 + RSA-key-pairs/README.md | 21 +++++++++++++++++++++ RSA-key-pairs/key-pair-generator.py | 20 ++++++++++++++++++++ RSA-key-pairs/requirements.txt | 1 + 4 files changed, 43 insertions(+) create mode 100644 RSA-key-pairs/README.md create mode 100644 RSA-key-pairs/key-pair-generator.py create mode 100644 RSA-key-pairs/requirements.txt diff --git a/README.md b/README.md index 7ef6576..4ec8173 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ So far, the following projects have been integrated to this repo: |[IMDB TV Series Info Extractor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/imdb_episode_ratings)|[Yash Raj Sarrof](https://github.com/yashYRS) | |[Yoda-speak Translator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/speak_like_yoda)|[sonniki](https://github.com/sonniki) | |[Medium Article Downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/medium_article_downloader)|[coolsonu39](https://github.com/coolsonu39)| +|[RSA Key Pair Generator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/RSA-key-pairs) | [Aditya Parikh](https://github.com/obiwan69) | ## How to use : diff --git a/RSA-key-pairs/README.md b/RSA-key-pairs/README.md new file mode 100644 index 0000000..f17c2fb --- /dev/null +++ b/RSA-key-pairs/README.md @@ -0,0 +1,21 @@ +# Python RSA Key Pair Generator +This python script will generate a private and public key pair using the RSA algorithm + +## Modules used + +Math +``` +import math +``` + +Random +``` +import random +``` + +#Usage +You can use the public and private key to encrypt and decrypt information +Run the python file and get key pairs or edit the code and define your custom bounds in the random limits +``` +random.randint(start,end) +``` diff --git a/RSA-key-pairs/key-pair-generator.py b/RSA-key-pairs/key-pair-generator.py new file mode 100644 index 0000000..f00c2bf --- /dev/null +++ b/RSA-key-pairs/key-pair-generator.py @@ -0,0 +1,20 @@ +#a simple RSA public key and private key pair generator +#using gcd from math module for coprimes +#and random for random numbers +import math +import random +p = random.randint(1,100) +q = random.randint(100,200) +if (math.gcd(p,q) == 1): + n = p * q + phi = (p-1)*(q-1) + k = 0 + e = random.randint(1,20000) + if (math.gcd(phi,e)==1): + for i in range(1,20000): + d = (((phi * i) + 1)/e) + if d.is_integer(): + k = d + break + print('Public key is: (',e,',',n,')') + print('Private key is: (',int(k),',',n,')') diff --git a/RSA-key-pairs/requirements.txt b/RSA-key-pairs/requirements.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/RSA-key-pairs/requirements.txt @@ -0,0 +1 @@ +