Captcha Generator
Generate customizable CAPTCHA images with distorted text, noise, and lines. Configure difficulty, character sets, and export as PNG.
About
CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) remains a frontline defense against automated form submissions, credential stuffing, and scraping bots. A weak CAPTCHA - low distortion, predictable character sets, no noise - is trivially defeated by modern OCR engines like Tesseract, which achieve > 95% accuracy on clean text. This generator produces challenge images with configurable distortion intensity d, noise density ρ, and character count n, rendering them onto an HTML Canvas with per-character rotation, scaling jitter, and overlapping interference lines. Characters are selected via cryptographically secure randomness (crypto.getRandomValues), and ambiguous glyphs (0/O, 1/l/I) can be excluded to reduce user frustration without compromising bot resistance.
This tool approximates production CAPTCHA systems but does not implement server-side verification. In a real deployment, the answer must never exist in client-side code. Use this to prototype visual difficulty, generate sample images for testing OCR pipelines, or produce one-off verification codes for low-risk scenarios. The exported PNG can be embedded in email forms or printed documents where interactive CAPTCHA services are unavailable.
Formulas
The total combinatorial keyspace K of a CAPTCHA with n characters drawn from an alphabet of size A is:
For an alphanumeric, case-sensitive set: A = 62. A 6-character CAPTCHA yields K = 626 ≈ 5.68 × 1010 combinations. Brute force at 1000 attempts per second would require ≈ 1.8 years without rate limiting.
Per-character rotation angle θ is sampled uniformly:
where dmax is the maximum rotation in radians. Baseline vertical jitter δy follows the same uniform distribution with amplitude jmax.
Sinusoidal warp applied to the final image displaces each pixel row:
where a = warp amplitude in pixels, f = frequency (number of wave cycles), and h = canvas height. This non-linear distortion prevents affine-based OCR correction.
Where: K = total keyspace, A = alphabet size, n = character count, θi = rotation of character i, dmax = max rotation angle, a = warp amplitude, f = warp frequency, h = image height.
Reference Data
| Parameter | Low Difficulty | Medium Difficulty | High Difficulty | Effect on OCR Resistance |
|---|---|---|---|---|
| Character Count (n) | 4 | 6 | 8 | More chars increase combinatorial space exponentially |
| Rotation Range | ±10° | ±20° | ±35° | Breaks OCR character segmentation |
| Noise Lines | 2 | 5 | 8 | Interferes with edge detection algorithms |
| Noise Dots | 30 | 80 | 150 | Salt-and-pepper noise degrades binarization |
| Font Size Jitter | ±2px | ±5px | ±10px | Prevents template matching attacks |
| Baseline Jitter | ±3px | ±8px | ±15px | Disrupts line segmentation heuristics |
| Color Variation | Monochrome | 3 colors | Per-character random | Defeats single-threshold binarization |
| Background Noise | Clean | Light gradient | Random arcs + gradient | Prevents simple background subtraction |
| Character Overlap | 0px | 3px | 6px | Merges connected components, hardest for OCR |
| Bezier Warp | None | Mild wave | Strong sinusoidal | Non-linear distortion defeats affine correction |
| Ambiguous Chars Excluded | Yes (0,O,1,l,I) | Partial (0,O) | No exclusions | Tradeoff: user accuracy vs. keyspace size |
| Charset: Digits Only | 10 symbols | 10 symbols | 10 symbols | Keyspace: 10n |
| Charset: Letters Only | 26 symbols | 26 symbols | 52 symbols | Keyspace: 52n (case-sensitive) |
| Charset: Alphanumeric | 36 symbols | 36 symbols | 62 symbols | Keyspace: 62n (case-sensitive) |
| OCR Accuracy (Tesseract v5) | >80% | 30 - 50% | <10% | Estimated; varies by font and preprocessing |