Git Product home page Git Product logo

rpg's Introduction

The third program exercise: Generate large enough random prime number

The program was implemented by Nguyen Tien Anh

Description:

The project allows to generate the large enough prime number for RSA Cryptosystem Purpose. The main.py file contains source code of program. The program makes sure that:

  1. The number generated was 3072 bits (large enough) in length.
  2. The number generated was randomly and hard enough to predict.
  3. The average time to generate each number is fast enough.

In the main.py file, I used os.urandom(384) to generate 3072 bit random number. Then I set the highest and lowest bit of the number to 1. After, checked the number was prime or not by advanceRabin_Miller() function. The detail of function as described in the slide. If the number was prime, then calculated time to generate from start time to the time in which the number was prime. If the time was in which range, increased counter of that range to 1. Finally, I consumed the result and print it to the console.

The result showed that:

  • 18 numbers were generated in range 0 to 1 second
  • 39 numbers were generated in range 1 to 2 seconds
  • 25 numbers were generated in range 2 to 3 seconds
  • 8 numbers were generated in range 3 to 4 seconds
  • 2 numbers were generated in range 4 to 5 seconds
  • 5 numbers were generated in range 5 to 6 seconds
  • 3 numbers were generated in range 6 to 7 seconds
  • and there was no number was generated in range 7 to 10 seconds

==> The program took 2.14 seconds in average to generate each prime number of the 100 first prime numbers.

Requirement:

Python language with version 3.x Then, run the command: pip install gmpy2 to install gmpy2 library.

Usage:

From terminal, in the folder, type the following command: python main.py

Wait for few minutes then the result will show in the console.

Copyright by Nguyen Tien Anh

rpg's People

Contributors

anhpc03 avatar

Watchers

 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.