mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2025-02-12 03:18:08 +00:00
* add yts_torrents project (#116) * add yts_torrents project * Added Python Script HacktoberFest 2019 (#128) * Added whatsapp-message Script * Update README.md * Script: Importance Checker (Updated Project List) (#132) * Add files to fork * Update README.md * Fixed ToDoBot link (#133) To Do bot link was using "-" instead of %20 Changed path to folders Removed full repo path to folders to make project robust to cloning as discussed on issue #139 on [AzureNotebooks](https://github.com/Microsoft/AzureNotebooks/issues/193). Fixed clean up photo directory name Fixed file organizer link Script: Importance Checker (Updated Project List) (#132) * Add files to fork * Update README.md Squash Squash Fixed ToDoBot link To Do bot link was using "-" instead of %20 parent 7c58b564104cdd1990492276292f04ec19009e57 author MatTerra <mateus.b.s.terra@gmail.com> 1574710004 -0300 committer MatTerra <mateus.b.s.terra@gmail.com> 1574710650 -0300 Squash Fixed ToDoBot link To Do bot link was using "-" instead of %20 Squash Changed path to folders Removed full repo path to folders to make project robust to cloning as discussed on issue #139 on [AzureNotebooks](https://github.com/Microsoft/AzureNotebooks/issues/193). Fixed ToDoBot link To Do bot link was using "-" instead of %20 Script: Importance Checker (Updated Project List) (#132) * Add files to fork * Update README.md * All changes made : Script added (#130) * Added whatsapp-message Script * Update README.md Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Revert "All changes made : Script added (#130)" (#135) This reverts commit74de9279f7
. * Add MIT license for project (#122) Signed-off-by: Kaushlendra Pratap <kaushlendrapratap.9837@gmail.com> * Add files via upload (#120) * Bump requests from 2.18.4 to 2.20.0 in /Tweets_Tool (#137) Bumps [requests](https://github.com/psf/requests) from 2.18.4 to 2.20.0. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/master/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.18.4...v2.20.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump urllib3 from 1.22 to 1.24.2 in /Tweets_Tool (#136) Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.22 to 1.24.2. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/master/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/1.22...1.24.2) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Added Image Recognition Script (#109) * Added face recognition script * Updated README Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Instagram Video Downloader (#94) * Instagram Video Downloader downloads all the videos from instagram post * Update README.md Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Wikipedia-Search (#87) * Create pywikisearch.py * Create README.md * Update README.md * Update README.md * Update README.md * Update pywikisearch.py * Create requirements.txt (#1) Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Added PX to REM, REM to Px as command line tools (#82) Co-authored-by: Atthaphon Urairat <aurairat@inetasia.com> Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Added an SSH host adder script, which allows you to add hosts to your ssh config file. (#76) Co-authored-by: NinoCosmic <nikola.dokoski@cosmicdevelopment.com> Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Added RSA Algorithm used in cryptography (#61) * Added RSA Algorithm * Update README.md * Create README.md * Update README.md * Add files via upload * Update README.md * Added RSA Algorithm Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * fix table allignment * python script which creates a map in html showing realtime covid stat… (#138) * python script which creates a map in html showing realtime covid status in india * remove extra space; fix allignment Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * fix to covid visualiser, sometimes deaths are null (#139) * Update README.md * Added a Random_Email_Generator to the list of projects! (#141) * Added Random Email Generator Python Script * Create README.md * Update README.md * Update Random_email_generator.py * Update Random_email_generator.py * Update README.md * Added Random Email Generator Python Script Co-authored-by: shub-garg <shubhamsgcool@gmail.com> * Ansh's Dictionary (#142) Added a project of English Theasauras * sudoku-solver (#144) * Update file-organizer.py * Update README.md * Add greeting.yml file * Add PR template for the project * update greetings.yml * update greetings.yml * Rename pull_request_template.md to PULL_REQUEST_TEMPLATE.md * Update greetings.yml * Delete greetings.yml * Added Py_Cleaner (#162) * Update README.md * Added Py_Cleaner * Toonify Scripts (#154) * Toonify Script Added * Update README.md * Update toonify-API-2.py * Added git automation to repo (#171) Added gitAutomation to README.md refactoring * Added Fibonacci_Sequence_Generator and updated main README.md accordingly (#173) * Tambola tickets generator (#169) * Adds utility to generate Tambola tickets * Adds utility to generate Tambola tickets * Added script to send messages to sqs in parallel (#165) * Added script to send messages to sqs in parallel * Update README.md * Added Codeforces Checker Python Script (#176) * python script to create github repo (#178) * Added python script to remove duplicate files from a directory (#179) * create script * create README.md * updated README.md * updated README.md * added batch image watermarker (#184) * added batch image watermarker * Create README.md * Update README.md to include project * add script for convert pdf to text (#183) Co-authored-by: pham.huu.quang <SUN-ASTERISK\pham.huu.quang@b121686-lt.sun-asterisk.com> * Update README.md * url_shortener files were added (#191) url_shortener.py skel was created the script has completed README.md description and requirements.txt were added The project was added to README.md * Python script to view wifi password. (#163) * Added wifi.py * Delete main.py * Create wifi_password.py * Create requirements.txt * Create README.md * Rename wifi_password.py to main.py * Update README.md * Update README.md Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Added Python made News Generator HackerNews (#174) * IMDB list querier project by Burak Bekci (#187) Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Added a Folder Manger Script. (#188) * Added Folder_Manager * Added Name to README.md Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Update README.md * Simple 2048 GUI tkinter game in Python3 (#194) * Simple 2048 GUI tkinter game in Python3 * added contributor to readme file * added elastic-snapshot script (#193) * added elastic-snapshot script * added project to the projects list * updated requirements.txt * Download page as pdf (#196) * Download page as PDF. * Contributor name. * Pudim page typo. * Added spotify downloader (#195) Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Github CLI tool added. (#198) * GithubBot added * add new project * Update README.md * Update README.md * Added Independent RSA Communication Algorithm (#199) * Added an indepedent RSA library Added an indepedent RSA library with no depedences (adapted to communication) * Created README.md Created README.md * Update README.md * Added project to README.md Added project "Independent RSA Communication Algorithm" to README.md Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Bump cryptography from 2.7 to 3.2 in /file-encrypt-decrypt (#201) Bumps [cryptography](https://github.com/pyca/cryptography) from 2.7 to 3.2. - [Release notes](https://github.com/pyca/cryptography/releases) - [Changelog](https://github.com/pyca/cryptography/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pyca/cryptography/compare/2.7...3.2) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add TranslateCLI (#200) * Added automation for converting JSON to YAML format. (#197) * Added automation for converting json to yaml format * Create Readme.md * Deletd the extra files * Added requirements.txt * Added name and project in project list Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Rock-Paper-Scissor Game (#202) * Rock-Paper-Scissor-Game * updated README.md * Add instagram link * remove quora link * add portfolio * update: portfolio (#208) * fix(README): remove msg from last commit * New Project (#206) * Added folder locker and hider * Update README.md * Bump py from 1.9.0 to 1.10.0 in /file-encrypt-decrypt (#209) Bumps [py](https://github.com/pytest-dev/py) from 1.9.0 to 1.10.0. - [Release notes](https://github.com/pytest-dev/py/releases) - [Changelog](https://github.com/pytest-dev/py/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/py/compare/1.9.0...1.10.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump cryptography from 3.2 to 3.3.2 in /file-encrypt-decrypt (#210) Bumps [cryptography](https://github.com/pyca/cryptography) from 3.2 to 3.3.2. - [Release notes](https://github.com/pyca/cryptography/releases) - [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pyca/cryptography/compare/3.2...3.3.2) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump urllib3 from 1.24.2 to 1.26.5 in /Tweets_Tool (#212) Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.24.2 to 1.26.5. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/1.24.2...1.26.5) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump urllib3 from 1.25.11 to 1.26.5 in /Github_Bot (#213) Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.25.11 to 1.26.5. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/1.25.11...1.26.5) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Added Image Compressor Script (#211) * Added Readme.md Gave a description of the project * Added Image_Compressor Added image compressor script and a sample image to compress the image file to a reduced size. * Updated README.md Added my name in Contributors list. * Created a Speed checking script in python 3 named TestMyInternetSpeed (#214) * speedtest using python * main python script for checking speeds * Add files via upload * Delete TestMySpeed.py * Delete requirements.txt * Delete README.md * Update README.md * Update README.md * Revert "Delete README.md" This reverts commit8d14c3b3e6
. reverted the accidentally commited readme file commit * added the readme file i deleted accidentally * Update README.md Co-authored-by: Dhruv Bansal <dhruvbansal@Dhruvs-MacBook-Air.local> * Bump requests from 2.18.4 to 2.20.0 in /Tweets_Tool (#215) Bumps [requests](https://github.com/psf/requests) from 2.18.4 to 2.20.0. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/master/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.18.4...v2.20.0) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump urllib3 from 1.24.2 to 1.26.5 in /Tweets_Tool (#216) Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.24.2 to 1.26.5. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/1.24.2...1.26.5) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com> * Bump requests from 2.18.4 to 2.20.0 in /Tweets_Tool (#217) Bumps [requests](https://github.com/psf/requests) from 2.18.4 to 2.20.0. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/master/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.18.4...v2.20.0) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add my script PLAGIARISM_DETECTOR to the repo (#218) * AI simulation for guessing the number (#219) * Add files via upload * Create README.md * Create Requirements * Update README.md * Added CSV to Excel writer (#222) * Added Cryptocurrency prices (#223) * Added Cryptocurrency prices * Update README.md * Add the word frequency counter (#225) * Battery notification (#227) * Create Battery_notification.py * Create README.md * Update README.md * Update README.md * Update README.md * Update README.md * add Harry Potter Cloak script using Open-CV (#228) * add Harry Potter Cloak script using Open-CV * add Indian Flag using Turtle * Delete README.md * Delete main.py * Update README.md * Update README.md (#146) * Csv_to_json (#224) * Added csv_to_json script * added requirements.txt file * added images * Added README.md * Added my details * Add the website URL detector (#230) * README fix (#231) * Updated README * Images fix * Link fix * fix broken hit counter button (#232) * add awesome repo button (#233) * Added Steg_Tool Script (#234) Co-authored-by: Shankar JP <shankarjp12@outlook.com> Co-authored-by: Mayank Nader <34679965+makkoncept@users.noreply.github.com> Co-authored-by: mukeshprasad <44356982+mukeshprasad@users.noreply.github.com> Co-authored-by: natesabrown <45186473+natesabrown@users.noreply.github.com> Co-authored-by: Mateus Berardo de Souza Terra <mateus.b.s.terra@gmail.com> Co-authored-by: Kaushlendra Pratap <41343571+Kaushl2208@users.noreply.github.com> Co-authored-by: Sarah Floris <sdf94@uw.edu> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: LOKESH KHURANA <35563030+theluvvkhurana@users.noreply.github.com> Co-authored-by: Shobhit Bhosure <38807205+shobhit99@users.noreply.github.com> Co-authored-by: Nissaar <34180849+Nissaar@users.noreply.github.com> Co-authored-by: Atthaphon Urairat <u.atthaphon@gmail.com> Co-authored-by: Atthaphon Urairat <aurairat@inetasia.com> Co-authored-by: Nikola Dokoski (Nino) <ninodokoskiot@hotmail.com> Co-authored-by: NinoCosmic <nikola.dokoski@cosmicdevelopment.com> Co-authored-by: Chinmay Rane <chinmayrane16@gmail.com> Co-authored-by: tushar5526 <30565750+tushar5526@users.noreply.github.com> Co-authored-by: joec237 <37048612+joec237@users.noreply.github.com> Co-authored-by: SHUBHAM GARG <52582943+shub-garg@users.noreply.github.com> Co-authored-by: shub-garg <shubhamsgcool@gmail.com> Co-authored-by: Ansh Dhingra <56676059+anshdhinhgra47@users.noreply.github.com> Co-authored-by: ayedaemon <39592651+ayedaemon@users.noreply.github.com> Co-authored-by: Abhishek <55457501+Abhishek-Dobliyal@users.noreply.github.com> Co-authored-by: Chetan Pandey <chetanpandey1266@gmail.com> Co-authored-by: loge1998 <38487437+loge1998@users.noreply.github.com> Co-authored-by: JohnWesleyK <59068112+JohnWesleyK@users.noreply.github.com> Co-authored-by: Synster <amandeepkalra.kalra@gmail.com> Co-authored-by: Jinam Shah <40169508+jinamshah@users.noreply.github.com> Co-authored-by: Jinesh Parakh <50925060+jineshparakh@users.noreply.github.com> Co-authored-by: HARISH KUMAR TIWARI <harishtiwary46@gmail.com> Co-authored-by: Aayushi Varma <59158445+aayuv17@users.noreply.github.com> Co-authored-by: Remco Halman <remco.halman@gmail.com> Co-authored-by: QuangPH <55747283+quangph-1686a@users.noreply.github.com> Co-authored-by: pham.huu.quang <SUN-ASTERISK\pham.huu.quang@b121686-lt.sun-asterisk.com> Co-authored-by: Sam Ebison <ebsa491@gmail.com> Co-authored-by: sagar627 <55939746+sagar627@users.noreply.github.com> Co-authored-by: Atharva Ashok Patil <39415890+Attupatil@users.noreply.github.com> Co-authored-by: Burak Bekci <bekciburak97@gmail.com> Co-authored-by: Harsh Raj <rafftar98@gmail.com> Co-authored-by: gitkp <47073116+gitkp11@users.noreply.github.com> Co-authored-by: Joe <joe@clanryan.us> Co-authored-by: Jeremias Moreira Gomes <j3r3miasmg@gmail.com> Co-authored-by: Abhilasha Sinha <43816262+Abhilasha06@users.noreply.github.com> Co-authored-by: dec0 <35975131+wi6n3l@users.noreply.github.com> Co-authored-by: Rodrigo Oliveira <rodrigo.redcode@gmail.com> Co-authored-by: stark117 <55136108+saksham117@users.noreply.github.com> Co-authored-by: Punit Sakre <punitsakre786@gmail.com> Co-authored-by: Rashmi Singh <72220428+rashmiprabhat567@users.noreply.github.com> Co-authored-by: Prajjwal Pathak <71623767+pyGuru123@users.noreply.github.com> Co-authored-by: Prathima Kadari <kadariprathima4@gmail.com> Co-authored-by: Dhruv Bansal <dhruvbansal237@gmail.com> Co-authored-by: Dhruv Bansal <dhruvbansal@Dhruvs-MacBook-Air.local> Co-authored-by: Akshita Singhal <56424809+akshitasinghal4444@users.noreply.github.com> Co-authored-by: ShadowHunter15 <72161983+ShadowHunter15@users.noreply.github.com> Co-authored-by: Muhammed Ali Dilek <xemeds@protonmail.com> Co-authored-by: Sonya Nikiforova <son.nik@mail.ru> Co-authored-by: Krishna Sharma <krishnasharma1386@gmail.com> Co-authored-by: TanmayNagdeve <55934827+TanmayNagdeve@users.noreply.github.com> Co-authored-by: MoiZ <techboyy6@gmail.com> Co-authored-by: shreyas-lab <68059145+shreyas-lab@users.noreply.github.com> Co-authored-by: Shankar Jayaprakash <79354504+shankarjp@users.noreply.github.com> Co-authored-by: Shankar JP <shankarjp12@outlook.com>
159 lines
4.6 KiB
Python
159 lines
4.6 KiB
Python
#Modulus (N) bit length, k.
|
||
#OUTPUT: An RSA key pair ((N,e),d) where N is the modulus, the product of two primes (N=pq) not exceeding k bits in length;
|
||
# e is the public exponent, a number less than and coprime to (p−1)(q−1);
|
||
# and d is the private exponent such that e*d ≡ 1 mod (p−1)*(q−1).
|
||
##############################################################
|
||
#Select a value of e from 3,5,17,257,65537 (easy operations)
|
||
# while p mod e = 1
|
||
# p = genprime(k/2)
|
||
#
|
||
# while q mode e = 1:
|
||
# q = genprime(k - k/2)
|
||
#
|
||
#N = p*q
|
||
#L = (p-1)(q-1)
|
||
#d = modinv(e, L)
|
||
#return (N,e,d)
|
||
|
||
from random import randrange, getrandbits
|
||
import base64
|
||
|
||
class rsa():
|
||
|
||
def __init__(self, e=4, k=5):
|
||
self.e = [3, 5, 17, 257, 65537][e]
|
||
self.k = [128, 256, 1024, 2048, 3072, 4096][k]
|
||
|
||
def is_prime(self, n, tests=128):
|
||
if n == 2 or n == 3:
|
||
return True
|
||
if n <= 1 or n % 2 == 0:
|
||
return False
|
||
s = 0
|
||
r = n - 1
|
||
while r & 1 == 0:
|
||
s += 1
|
||
r //= 2
|
||
for _ in range(tests):
|
||
a = randrange(2, n - 1)
|
||
x = pow(a, r, n)
|
||
if x != 1 and x != n - 1:
|
||
j = 1
|
||
while j < s and x != n - 1:
|
||
x = pow(x, 2, n)
|
||
if x == 1:
|
||
return False
|
||
j += 1
|
||
if x != n - 1:
|
||
return False
|
||
return True
|
||
|
||
def genprime(self, length=1024):
|
||
p = 1
|
||
while len(bin(p))-2 != length:
|
||
p = list(bin(getrandbits(length)))
|
||
p = int(''.join(p[0:2] + ['1', '1'] + p[4:]), 2)
|
||
p += 1 if p % 2 == 0 else 0
|
||
|
||
ip = self.is_prime(p)
|
||
while not ip:
|
||
p += 2
|
||
ip = self.is_prime(p)
|
||
|
||
return p
|
||
|
||
def egcd(self, a, b):
|
||
if a == 0:
|
||
return (b, 0, 1)
|
||
else:
|
||
g, y, x = self.egcd(b % a, a)
|
||
return (g, x - (b // a) * y, y)
|
||
|
||
def modinv(self, a, m):
|
||
g, x, y = self.egcd(a, m)
|
||
if g != 1:
|
||
raise Exception('modular inverse does not exist')
|
||
else:
|
||
return x % m
|
||
|
||
def get_creds(self, e, k):
|
||
N = 0
|
||
while len(bin(int(N)))-2 != k:
|
||
p = self.genprime(int(k/2))
|
||
while pow(p, 1, e) == 1:
|
||
p = self.genprime(int(k/2))
|
||
q = self.genprime(k - int(k/2))
|
||
while pow(q, 1, e) == 1 and q == p:
|
||
q = self.genprime(k - int(k/2))
|
||
N = p*q
|
||
L = (p-1)*(q-1)
|
||
d = self.modinv(e, L)
|
||
return p, q, (d, e, N)
|
||
|
||
def get_keys(self):
|
||
p, q, creds = self.get_creds(self.e, self.k)
|
||
return creds
|
||
|
||
def save_keys(self, filename="keys.k"):
|
||
keys = self.get_keys()
|
||
with open(filename, "w", encoding="utf-8") as file:
|
||
file.write(str(keys[0]) + "\n" + str(keys[1]) + "\n" + str(keys[2]))
|
||
|
||
def load_keys(self, filename="keys.k"):
|
||
with open(filename, "r", encoding="utf-8") as file:
|
||
f = file.read().split("\n")
|
||
d = int(f[0])
|
||
e = int(f[1])
|
||
n = int(f[2])
|
||
return (d, e, n)
|
||
|
||
def encrypt(self, ke, plaintext):
|
||
key, n = ke
|
||
b64_string = base64.b64encode(plaintext.encode("utf-8")).decode("utf-8")
|
||
ready_code = []
|
||
for char in list(b64_string):
|
||
ready_code.append('0' * (3 - len(str(ord(char)))) + str(ord(char)))
|
||
ready_code = int("1" + "".join(ready_code))
|
||
cipher = pow(ready_code, key, n)
|
||
return cipher
|
||
|
||
def decrypt(self, kd, ciphertext):
|
||
key, n = kd
|
||
plain_list = list(str(pow(ciphertext, key, n)))[1:]
|
||
plain = []
|
||
count = 1
|
||
temp = ""
|
||
for i in plain_list:
|
||
if count != 4:
|
||
temp += i
|
||
count += 1
|
||
else:
|
||
plain.append(temp)
|
||
temp = i
|
||
count = 2
|
||
plain.append(temp)
|
||
plain_list = plain
|
||
plain = base64.b64decode(''.join([chr(int(char)) for char in plain_list])).decode("utf-8")
|
||
return plain
|
||
|
||
encryption = rsa()
|
||
keys = encryption.get_keys()
|
||
|
||
d = keys[0]
|
||
e = keys[1]
|
||
n = keys[2]
|
||
|
||
print("key: \n" + str(e) + "/" + str(n))
|
||
|
||
while True:
|
||
choose = input("Encrypt (e)/ Decrypt (d) > ")
|
||
if choose == "e":
|
||
e, n = input("insert key > ").split("/")
|
||
to_encrypt = input("message to encrypt > ")
|
||
a = encryption.encrypt((int(e), int(n)), to_encrypt)
|
||
print(a)
|
||
elif choose == "d":
|
||
to_decrypt = input("message to decrypt > ")
|
||
a = encryption.decrypt((d, n), to_decrypt)
|
||
print(a)
|