- libgpw-go
- Features
- Installation
- How to use the library
- Usage
- API
- Testing
- Tools
- Algorithm
- License
- Credits
A Go library for generating "pronounceable" passwords using trigram frequency analysis of English text. It is a Go port of the Java library: libgpw
- Generate pronounceable passwords that are easier to remember
- Generate passphrases (multiple words separated by spaces)
- Modify passwords to add:
- Capital letters
- Numbers
- Symbols (!@#$%^&*()+)
- Uses cryptographically secure random number generation
go get github.com/muquit/libgpw-goCreate a new project, initialize a module, and fetch the library, for example:
mkdir mypassgen
cd mypassgen
go mod init mypassgen
go get github.com/muquit/libgpw-go@v1.0.1Your go.mod will look like (the go version reflects your local Go installation):
module mypassgen
go 1.25.1
require github.com/muquit/libgpw-go v1.0.1
Create main.go:
package main
import (
"fmt"
"log"
"github.com/muquit/libgpw-go"
)
func main() {
passwords, err := gpw.GeneratePasswords(5, 8)
if err != nil {
log.Fatal(err)
}
for i, pwd := range passwords {
fmt.Printf("Password %d: %s\n", i+1, pwd)
}
}Run it:
go run main.gopackage main
import (
"fmt"
"log"
"github.com/muquit/libgpw-go"
)
func main() {
// Generate 5 passwords of length 8
passwords, err := gpw.GeneratePasswords(5, 8)
if err != nil {
log.Fatal(err)
}
for i, pwd := range passwords {
fmt.Printf("Password %d: %s\n", i+1, pwd)
}
// Generate a single password
password, err := gpw.GenerateOnePassword(10)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Single password: %s\n", password)
}// Generate 3 passphrases with 4 words each, each word 5 characters long
passphrases, err := gpw.GeneratePassphrases(3, 4, 5)
if err != nil {
log.Fatal(err)
}
for i, phrase := range passphrases {
fmt.Printf("Passphrase %d: %s\n", i+1, phrase)
}
// Generate a single passphrase
passphrase, err := gpw.GenerateOnePassphrase(4, 6)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Single passphrase: %s\n", passphrase)// Generate a password
password, _ := gpw.GenerateOnePassword(8)
fmt.Printf("Original: %s\n", password)
// Add capitals only
modified := gpw.ModifyPassword(password, true, false, false)
fmt.Printf("With capitals: %s\n", modified)
// Add capitals and numbers
modified = gpw.ModifyPassword(password, true, true, false)
fmt.Printf("With capitals and numbers: %s\n", modified)
// Add capitals, numbers, and symbols
modified = gpw.ModifyPassword(password, true, true, true)
fmt.Printf("With all modifications: %s\n", modified)GeneratePasswords(count, length int) ([]string, error)- Generate multiple passwordsGenerateOnePassword(length int) (string, error)- Generate a single passwordGeneratePassphrases(count, numWords, wordLength int) ([]string, error)- Generate multiple passphrasesGenerateOnePassphrase(numWords, wordLength int) (string, error)- Generate a single passphrase
ModifyPassword(password string, capitalize, numerals, symbols bool) string- Modify a password to add capitals, numbers, and/or symbols
# Run tests
go test
# Run tests with coverage
go test -cover
# Run benchmarks
go test -bench=.Pre-built binaries are available on the Releases page. Download the archive for your platform and extract it. The binary inside is named with the platform suffix, for example:
Linux/macOS
tar -xzf gpw-v1.0.1-linux-amd64.d.tar.gz
sudo cp gpw-v1.0.1-linux-amd64 /usr/local/bin/gpwWindows
Extract the zip and rename gpw-v1.0.1-windows-amd64.exe to gpw.exe, then copy it to a directory in your PATH.
Alternatively, build from source:
make cli
sudo cp gpw /usr/local/bin/Basic usage:
# Generate 5 passwords of length 16 (defaults)
gpw
# Generate 10 passwords of length 12
gpw -n 10 -l 12
# Add capitals, digits, and symbols
gpw -c -d -y
# Spell out passwords using NATO phonetic alphabet
gpw -s
# Show version
gpw -VOptions:
Usage: gpw [-cdhsVy] [-l=<passwordLength>] [-n=<numberOfPasswords>]
-c, --capitalize Add uppercase letters
-d, --digits Add numerals
-h, --help Show this help message and exit
-l, --length Password length (default: 16)
-n, --number Number of passwords to generate (default: 5)
-s, --spell Spell out password using NATO phonetic alphabet
-V, --version Print version information and exit
-y, --symbols Add symbols
Please visit gpw-web demo
A browser-based interface is included in the gpw-web/ directory. It runs entirely client-side using WebAssembly.
To use it, serve the directory with any static file server. A few options:
Python (3.x)
cd gpw-web
python3 -m http.server 8080Python (2.x)
cd gpw-web
python -m SimpleHTTPServer 8080Node.js
cd gpw-web
npx serve .Ruby
cd gpw-web
ruby -run -e httpd . -p 8080Then open http://localhost:8080 in a browser.
Alternatively, copy the gpw-web/ directory to your web server's document root (e.g. /var/www/html/gpw-web) and access it at http://yourserver/gpw-web/.
Note: the browser must support WebAssembly (all modern browsers do). Opening index.html directly as a file:// URL will not work due to CORS restrictions on loading .wasm files.
The library uses trigram frequency analysis:
- A 3D array contains frequency counts for all possible 3-letter combinations (trigrams) in English text
- Password generation starts with a randomly selected trigram based on weighted probabilities
- Each subsequent letter is chosen based on the frequency of trigrams formed with the previous two letters
- This creates pronounceable passwords that follow English language patterns
The trigram data was derived from a large corpus of English text and contains 17,576 possible three-letter combinations (26^3).
MIT License
- Original GPW algorithm: Tom Van Vleck https://www.multicians.org/thvv/gpw.html
- My port as Java Library libgpw
- Go implementation with assistance from Claude AI Sonnet 4.6
TOC is created by https://github.com/muquit/markdown-toc-go on Jun-03-2026