Crates.io | rust-miller-rabin |
lib.rs | rust-miller-rabin |
version | 0.1.4 |
source | src |
created_at | 2024-04-22 20:04:13.141949 |
updated_at | 2024-05-02 10:12:40.080446 |
description | A Rust implementation of the Miller-Rabin primality test |
homepage | |
repository | |
max_upload_size | |
id | 1216589 |
size | 13,339 |
A complete Rust implementation of the Miller Rabin primality test algorithm. View on github: https://github.com/callum-fortune/rust-miller-rabin
The Miller Rabin algorithm, whilst incredibly accurate has been known to produce false positives in some cases. This is because the algorithm is officially classed as a probabilistic primality test. Proceed to use this project with that knowledge. Read more here...
The project is based heavily on this implementation...
I am yet to be made aware of the higher limit of this project, I have tested the code with prime numbers more than 300 characters in length and as little as one, without fail.
I created this project on my journey to implenting a basic Rust RSA implementation. This is a common use case for the Miller-Rabin test and there is a good chance that you are in the same process. Be warned that any implementations of your own that use this code are done at your own risk.
I have packaged this project as a Rust library however I have included a main.rs file to show the code in a working state. This can be found in the src folder or just ran with:
cargo build
cargo run
If you wish to use this as a library you can import and use it as follows:
use rust_miller_rabin::miller_rabin::miller_rabin
fn is_prime(number: BigInt) -> bool {
println!("Checking prime");
return miller_rabin(&number);
}
I have included tests for the project which will test small primes, large primes, small non-primes and large non-primes. Run these with:
cargo test
^Not to insult your intelligence