Coder Social home page Coder Social logo

ggint's Introduction

ggint

Poor man's long integer arithmetic operations.

  • Header-only
  • No 3rd party libraries

Numbers are represented as array of bytes:

N = a[0] + a[1]*256 + a[2]*256^2 + a[3]*256^3 + ...

The main goal was to learn how Miller-Rabin primality test works and try to generate some big prime numbers from scratch. The code is not optimized and probably has bugs and most likely this is not the correct way to implement efficient long integer arithmetic. Nevertheless, it manages to find random prime and safe prime numbers in reasonable time (although much slower than openssl):

$ ./find_prime 256

    Usage: ./find_prime nbits
    Generating small primes for fast sieve check
    Max prime in sieve = 4093
    Searching for 256-bit prime ...
    .........
    Found prime p:
     -                p : 131 180  43 109 186 157  78  54 244  74  36  37  75 253  52 172 251  61  58 217 167  74 241 118  74  65  52   3 103 110 254 224
                Decimal : 101767619206415467646517001340499112030636580664836015053725702323129188856963

$  openssl prime 101767619206415467646517001340499112030636580664836015053725702323129188856963

    101767619206415467646517001340499112030636580664836015053725702323129188856963 is prime

$ ./find_safe_prime 192

    Usage: ./find_safe_prime nbits
    Generating small primes for fast sieve check
    Max prime in sieve = 4093
    Searching for 192-bit safe prime ...
    ......
    Found safe prime p:
     -                p :  67 150 125  76 190  74 243 119 255  95 250 199  86 185 239 251 115 251  15 193 148 232  55 211
                Decimal : 5179059918294645595326237229226656885717064063222063928899
     -          (p-1)/2 :  33 203  62  38  95 165 249 187 255  47 253  99 171 220 247 253 185 253 135  96  74 244 155 105
                Decimal : 2589529959147322797663118614613328442858532031611031964449

$ openssl prime 5179059918294645595326237229226656885717064063222063928899

    5179059918294645595326237229226656885717064063222063928899 is prime

$ openssl prime 2589529959147322797663118614613328442858532031611031964449

    2589529959147322797663118614613328442858532031611031964449 is prime

ggint's People

Contributors

ggerganov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sahwar dn9uy3n

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.