Skip to content

Instantly share code, notes, and snippets.

@mjgarton
Created February 25, 2019 13:47
Show Gist options
  • Save mjgarton/04af8f66d705679d57e314a888c98046 to your computer and use it in GitHub Desktop.
Save mjgarton/04af8f66d705679d57e314a888c98046 to your computer and use it in GitHub Desktop.
reverses bill customer account number id into bill customer account number.
package main
import (
"bufio"
"fmt"
"log"
"os"
"github.com/google/uuid"
)
/*
This reads a line by line input of customer account ids until EOF, and finds the related customer numbers by brute force.
Example : `echo 8b0bc34b-ba28-59bf-a87a-6e923e395069 | go run accountno.go`
*/
var (
accountNSUUID = uuid.NewSHA1(uuid.UUID{}, []byte("customer")) // "customer" is for compatibility reasons
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
wanted, err := uuid.Parse(scanner.Text())
if err != nil {
return err
}
for i := 1; i <= 9999999; i++ {
no := fmt.Sprintf("%07d", i)
u := uuid.NewSHA1(accountNSUUID, []byte(no))
if wanted == u {
fmt.Printf("account id %s relates to account number %s\n", wanted, no)
}
}
}
if err := scanner.Err(); err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment