diffsquare 0.5.0

Fast and efficient Fermat factorization CLI
Documentation
# diffsquare

[![Crates.io](https://img.shields.io/crates/v/diffsquare.svg)](https://crates.io/crates/diffsquare)
[![Crates.io Downloads](https://img.shields.io/crates/d/diffsquare.svg)](https://crates.io/crates/diffsquare)
[![Docs.rs](https://docs.rs/diffsquare/badge.svg)](https://docs.rs/diffsquare)
[![License](https://img.shields.io/crates/l/diffsquare)](./LICENSE)

---

## From the Author

Created by [Abhrankan Chakrabarti](https://github.com/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`](https://docs.rs/malachite/) crate for high-performance arbitrary-precision arithmetic.

## Recent Update โ€“ v0.5.0

๐Ÿš€ **New in v0.5.0:** parallel factorization using [`rayon`](https://docs.rs/rayon)

* Leverages multiple threads to speed up Fermat's Difference of Squares method.
* Improved performance on large semiprimes, especially with batch input (`--stdin`).
* No changes required to existing CLI usage โ€” parallelism is automatic!

---

### 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 [`rayon`]https://docs.rs/rayon for faster factorization on multi-core systems (since v0.5.0).
* Support for decimal, hexadecimal, and scientific notation input.
* Command-line interface with interactive fallback.
* Quiet mode (`-q`) disables interactive prompts and hides intermediate output โ€” useful for piping or scripting.
* JSON output mode (`--json`) for scripting and automation.
* `--time-only` flag for displaying only the execution time (useful for benchmarking).
* Batch factorization using `--stdin` to read multiple newline-separated numbers from standard input (e.g., via piping or redirection).
* Optional control over iteration starting point and precision.
* Scientific notation used in verbose mode for large integer readability.
* Execution time displayed after successful factorization.

> GitHub Repository: [`diffsquare`]https://github.com/Abhrankan-Chakrabarti/diffsquare

---

## Installation

Install via Cargo:

```bash
cargo install diffsquare
```

Ensure `$HOME/.cargo/bin` is in your `PATH`:

```bash
export PATH="$HOME/.cargo/bin:$PATH"
```

---

## Build Instructions

To build from source manually:

```bash
git clone https://github.com/Abhrankan-Chakrabarti/diffsquare.git
cd diffsquare
cargo build --release
```

---

## ๐Ÿ”ง Usage Examples

Run `diffsquare` interactively or use flags for automation:

```bash
# ๐Ÿ”น Fully interactive: prompts for modulus, iteration, and precision
diffsquare

# ๐Ÿ”น Provide a decimal modulus
diffsquare -n 17976931348623159077293051907890247336179769789423065727343008115

# ๐Ÿ”น Provide a hexadecimal modulus
diffsquare -n 0xDEADBEEFCAFEBABE1234567890

# ๐Ÿ”น Specify starting iteration (modulus still required)
diffsquare -n 0xC0FFEE123456789 -i 1000000

# ๐Ÿ”น Use custom precision for verbose scientific output
diffsquare -n 0xABCD1234 -p 30

# ๐Ÿ”น Combine all options and suppress output (precision not required in quiet mode)
diffsquare -n 0xCAFED00D1234 -i 50000 -q

# ๐Ÿ”น JSON output for scripting and automation
diffsquare -n 0xC0FFEE123456789 --json

# ๐Ÿ”น Show only execution time (no output of factors)
diffsquare -n 0xCAFED00D1234 --time-only

# ๐Ÿ”น Check installed version
diffsquare --version

# ๐Ÿ”น โ™ป๏ธ Batch factorization from standard input (stdin)
# Example: echo or cat piped into the CLI
echo -e "2761929023323646159\n3189046231347719467" | diffsquare --stdin

# Example: cat a file or redirect any input to stdin
cat numbers.txt | diffsquare --stdin

# Example: cat piped into diffsquare with threads and JSON output
cat numbers.txt | diffsquare --stdin --threads 4 --json
```

### 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`      | Print result as JSON (suppresses all other output)              |
|       | `--time-only` | Display only the execution time (useful for benchmarking)       |
|       | `--stdin`     | Read newline-separated numbers from standard input              |
|       | `--threads`   | Number of threads for parallel factorization (default: 1)       |
| `-h`  | `--help`      | Show usage help                                                 |
| `-v`  | `--version`   | Show version                                                    |

---

## Tags

**Tags**
`#RustLang` `#NumberTheory` `#OpenSource` `#BigInteger` `#Cryptography` `#Fermat` `#AbhrankanChakrabarti` `#Malachite`