Skip to content

alexHoggett/rsa

Repository files navigation

RSA implementation in python3

Requires Python 3

Usage:

$ ./rsa.py -h
Usage: rsa.py [options]

Simple command line program for RSA encryption

Options:
  -h, --help            show this help message and exit
  -g, --generate-keys   Generate public and private keys optionally specify
                        the size of p and q with --pqsize
  -p PQSIZE, --pqsize=PQSIZE
                        Specify the size of p and q
  -e MESSAGE_FILE, --encrypt=MESSAGE_FILE
                        encrypt message in file
  -d CIPHER_FILE, --decrypt=CIPHER_FILE
                        decrpyt message
  -f FILENAMES, --loadkey/s=FILENAMES
                        Load key files

# Generate
$ ./rsa.py -g -p 100

Generating keys
----------------------------
SIZE OF r in bits 896
Size of d in bits 896
----------------------------
Generated keys!
Public key stored in key_rsa.pub
Private key stored in key_rsa. Keep this secret!
----------------------------

# Encrypt
$ ./rsa.py -e plaintext.txt -f key_rsa.pub
Generated file cipher.json
# Decrypt
$ ./rsa.py -d cipher.json -f key_rsa.pub key_rsa
Decrypted message and written to file decrypted.txt

# Brute force guess private key
$ ./charlie.py -m key_rsa.pub
PUBLIC KEY:
{'e': 182563540195118449525715743066280327625184038035207222334715849889969642101507533546585753619751408730068734428211954001562239467439789039831639637057040548198771509522118711936150347935694740292498929420726697834713736136428873, 'n': 2195119608721297415877037512242786464996825673990629768938344627911919103837080326171652428087249155060316396079847604482382995126555569316266740618979906382149564614431429621323031661908407730211089857950683432215713792861235009}
--------------------------------------------------------------------------------------------
---------------- Cipher test message -------------------------------------------------------
--------------------------------------------------------------------------------------------
------------- c:  294788308519134333270846593857284905135857455373442198583783289201022407895389074903207314020181398353083306296977860538575798552853569209416163905920722974371423187378361919750018121989000251222185828499048068211842254020894903
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>BRUTE FORCING Guessing private key>>>>>>>>>>>>>>>>>>>>>>
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
--------------------------------- Tried 123901 times ---------------------------------------

You may need to make the file executable with:

chmod +x rsa.py

About

A Python implementation of the RSA algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages