Coder Social home page Coder Social logo

zerobone / pollardrsacracker Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 3.0 30 KB

RSA cracking algorithm based on Pollard factorization (Pollard's p-1 method).

License: MIT License

Python 100.00%
cracking-ciphers pollard pollard-p-1 rsa rsa-cryptography rsa-decryption

pollardrsacracker's Introduction

PollardRsaCracker

This is my implementation of RSA cracking algorithm based on Pollard factorization. It will work if the numbers p - 1 and q - 1 that form n = p * q (as a part of the public key, p and q are prime), have no large maximum prime power factors. Of course, all modern RSA implementations don't have this security issue so this is more of an educational project.

Usage

In order to start the script, simply run python cracker.py

You will need 4 inputs:

  1. n - the modulus in the public key so that m = c ^ d mod n where m is the message, c is the encrypted message, d is the private key.
  2. e - the second public key component (so that gcd(e, phi(n)) = 1).
  3. c - the encrypted message.
  4. b - the maximum prime factor of n. This field is optional. However, if you leave it blank, the brute-force algorithm will be used for factorizing n.

Demo

Enter n (as part of the public key): 186444745729857899758373984272541398503249351266417000699738642133172271283265124803102459
Enter e (as part of the public key): 65537
Enter c (the encrypted message to decrypt): 159178142916077677757648147687519523540045276157456113470673097514775229976995968698190914
Enter b (the maximum prime factor in n, optional): 200000
Factorizing n with the Pollard algorithm...
k has 86871 digits
Trying to solve with a = 2
(a ^ k mod n) - 1 = 95072790833932492612013226959843266212858324985456485206430737027466196168851937286400160
p = 2962244945158622279601750283735698362054297
q = 62940354083336669282335053470277744418281466547
Factorizing complete.
phi(n) = 186444745729857899758373984272541398503249288323100672417910737518517050721785008159581616
Solving e * d = 1 mod phi(n) with the euklidian algorithm...
d (private key) = 144519783985790947216463957780263103956010556583510294319695217448779562333745493606767873
m (decrypted message) = 2020

Demo with small numbers

Brute-force

Enter n (as part of the public key): 493
Enter e (as part of the public key): 45
Enter c (the encrypted message to decrypt): 56
Enter b (the maximum prime factor in n, optional):
Factorizing n with the Bruteforce algorithm...
p = 17
q = 29
Factorizing complete.
phi(n) = 448
Solving e * d = 1 mod phi(n) with the euklidian algorithm...
d (private key) = 229
m (decrypted message) = 490

Pollard

Enter n (as part of the public key): 493
Enter e (as part of the public key): 45
Enter c (the encrypted message to decrypt): 56
Enter b (the maximum prime factor in n, optional): 493
Factorizing n with the Pollard algorithm...
k has 216 digits
Trying to solve with a = 2
(a ^ k mod n) - 1 = 0
Trying to solve with a = 3
(a ^ k mod n) - 1 = 0
Trying to solve with a = 4
(a ^ k mod n) - 1 = 0

...

Trying to solve with a = 509
(a ^ k mod n) - 1 = 0
Trying to solve with a = 510
(a ^ k mod n) - 1 = 203
p = 29
q = 17
Factorizing complete.
phi(n) = 448
Solving e * d = 1 mod phi(n) with the euklidian algorithm...
d (private key) = 229
m (decrypted message) = 490

Credits

License

Copyright (c) 2020 Alexander Mayorov.

This project is licenced under the MIT Licence.

Please leave a copyright notice if you use/modify this software or parts of it.

For more information see the LICENCE file.

pollardrsacracker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.