Created
February 25, 2019 13:47
-
-
Save mjgarton/04af8f66d705679d57e314a888c98046 to your computer and use it in GitHub Desktop.
reverses bill customer account number id into bill customer account number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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