diffsquare
From the Author
Created by Abhrankan Chakrabarti, this project implements an efficient version of Fermatโs Difference of Squares method for factoring large integers. Written in Rust, it leverages the malachite crate for high-performance arbitrary-precision arithmetic.
Recent Update โ v0.7.1
๐ New in v0.7.1:
-
โ Clarified
--threadsbehavior- The
--threadsflag now explicitly applies only to batch factorization modes (--stdinor--input). - Default thread count matches the number of logical CPUs when batch mode is active (Rayon default).
- Updated README and help text to accurately reflect this behavior.
- The
-
โ Improved handling of single modulus input
- Prevents accidental fallback to interactive mode when input is piped without
--stdinor--input. - Ensures cleaner error messages in quiet, JSON, CSV, or time-only modes when no modulus is provided.
- Prevents accidental fallback to interactive mode when input is piped without
-
๐ Miscellaneous
- Minor code cleanup and documentation refinements.
- Updated internal comments for better maintainability.
Key Features
diffsquare is a fast and lightweight CLI utility for factoring large integers using Fermatโs Difference of Squares method.
- Efficient Fermat's Difference of Squares factorization.
- Parallelized using
rayonfor faster factorization on multi-core systems (since v0.5.0). - Optional file input for batch factorization (
--input) (new in v0.7.0). - Optional file output with
--outputto save results (since v0.6.0). - Control thread count for batch processing with
--threads(new in v0.7.0). - Progress bar for file and stdin batch input (new in v0.7.0).
- Optional
--timeout Nto limit maximum time per factorization in milliseconds (since v0.6.1). - CSV output support via
--csvflag (since v0.6.1). - JSON output mode (
--json) for scripting and automation (since v0.3.0). - Quiet mode (
-q) disables prompts and hides intermediate output โ ideal for scripting. --time-onlyflag for showing only execution time โ useful for benchmarking (since v0.3.1).- Batch factorization via
--stdin(since v0.4.0). - Support for decimal, hexadecimal, and scientific notation input.
- Command-line interface with interactive fallback.
- Optional control over iteration starting point (
--iter) and precision (--prec). - Scientific notation used in verbose mode for large integer readability.
- Execution time displayed after successful factorization.
GitHub Repository:
diffsquare
Installation
Install via Cargo:
Ensure $HOME/.cargo/bin is in your PATH:
Build Instructions
To build from source manually:
๐ง Usage Examples
Run diffsquare interactively or use flags for automation:
# ๐น Fully interactive: prompts for modulus
# ๐น Provide a decimal modulus
# ๐น Provide a hexadecimal modulus
# ๐น Specify starting iteration
# ๐น Use custom precision for verbose scientific output
# ๐น Quiet mode, suppress intermediate output
# ๐น JSON output for scripting
# ๐น Show only execution time (for benchmarking)
# ๐น Batch factorization from stdin
|
# ๐น Batch factorization from file input
# ๐น Batch with threads and JSON output
# ๐น Batch with CSV output and save to file
Command-Line Flags
| Short | Long | Description |
|---|---|---|
-n |
--mod |
Number to factor (supports 0x for hex or scientific notation) |
-i |
--iter |
Starting iteration value |
-p |
--prec |
Precision for verbose scientific output |
-q |
--quiet |
Suppress prompts and intermediate output |
--json |
Output result in JSON format | |
--csv |
Output result as CSV | |
--time-only |
Show only execution time | |
--stdin |
Read newline-separated input from stdin | |
--input |
Read newline-separated input from file | |
--threads |
Number of threads for batch factorization (--stdin / --input) (default: logical CPUs) |
|
--output |
Output results to file | |
--timeout |
Timeout in milliseconds for each factorization | |
-h |
--help |
Show usage help |
-v |
--version |
Show version |
Tags
Tags
#RustLang #NumberTheory #OpenSource #BigInteger #Cryptography #Fermat #AbhrankanChakrabarti #Malachite