Skip to content

muquit/libgpw-go

Repository files navigation

Table Of Contents

libgpw-go

A Go library for generating "pronounceable" passwords using trigram frequency analysis of English text. It is a Go port of the Java library: libgpw

Features

  • 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

Installation

go get github.com/muquit/libgpw-go

How to use the library

Create 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.1

Your 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.go

Usage

Generate Passwords

package 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 Passphrases

// 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)

Modify Passwords

// 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)

API

Password Generation

  • GeneratePasswords(count, length int) ([]string, error) - Generate multiple passwords
  • GenerateOnePassword(length int) (string, error) - Generate a single password
  • GeneratePassphrases(count, numWords, wordLength int) ([]string, error) - Generate multiple passphrases
  • GenerateOnePassphrase(numWords, wordLength int) (string, error) - Generate a single passphrase

Password Modification

  • ModifyPassword(password string, capitalize, numerals, symbols bool) string - Modify a password to add capitals, numbers, and/or symbols

Testing

# Run tests
go test

# Run tests with coverage
go test -cover

# Run benchmarks
go test -bench=.

Tools

CLI (gpw)

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/gpw

Windows

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 -V

Options:

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

Web Interface (gpw-web)

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 8080

Python (2.x)

cd gpw-web
python -m SimpleHTTPServer 8080

Node.js

cd gpw-web
npx serve .

Ruby

cd gpw-web
ruby -run -e httpd . -p 8080

Then 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.

Screenshots

alt image1

alt image2

alt image3

Algorithm

The library uses trigram frequency analysis:

  1. A 3D array contains frequency counts for all possible 3-letter combinations (trigrams) in English text
  2. Password generation starts with a randomly selected trigram based on weighted probabilities
  3. Each subsequent letter is chosen based on the frequency of trigrams formed with the previous two letters
  4. 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).

License

MIT License

Credits


TOC is created by https://github.com/muquit/markdown-toc-go on Jun-03-2026

About

Pronounceable password generator - Go library with CLI and WASM web GUI

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors