|
|
@@ -0,0 +1,86 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import "encoding/hex"
|
|
|
+import "crypto/md5"
|
|
|
+import "strconv"
|
|
|
+import "strings"
|
|
|
+import "fmt"
|
|
|
+import "os"
|
|
|
+
|
|
|
+func string2Md5(input string, incr int) string {
|
|
|
+ inputBytes := []byte(input + strconv.Itoa(incr))
|
|
|
+ hashed := make([]byte, 16)
|
|
|
+
|
|
|
+ for i, j := range(md5.Sum(inputBytes)) {
|
|
|
+ hashed[i] = j
|
|
|
+ }
|
|
|
+
|
|
|
+ result := hex.EncodeToString(hashed)
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+func ex1(doorId string) string {
|
|
|
+ var result string
|
|
|
+
|
|
|
+ for i := 0 ; len(result) < 8; i++ {
|
|
|
+ hashed := (string2Md5(doorId, i))
|
|
|
+ if (strings.HasPrefix(hashed, "00000")) {
|
|
|
+ result += string(hashed[5])
|
|
|
+
|
|
|
+ fmt.Printf(result)
|
|
|
+ for j := len(result); j < 8; j++ {
|
|
|
+ fmt.Printf("_")
|
|
|
+ }
|
|
|
+ fmt.Printf("\n")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+func isDone(in []rune) bool {
|
|
|
+ res := len(in)
|
|
|
+
|
|
|
+ for i := 0; i < len(in); i++ {
|
|
|
+ if in[i] != 0 {
|
|
|
+ res--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res == 0
|
|
|
+}
|
|
|
+
|
|
|
+func ex2(doorId string) string {
|
|
|
+ result := make([]rune, 8)
|
|
|
+
|
|
|
+ for i := 0 ; true ; i++ {
|
|
|
+ hashed := (string2Md5(doorId, i))
|
|
|
+ if (strings.HasPrefix(hashed, "00000")) {
|
|
|
+ if (hashed[5] <= '7') {
|
|
|
+ if (result[hashed[5] - '0'] == 0) {
|
|
|
+ result[hashed[5] - '0'] = rune(hashed[6])
|
|
|
+ for j := 0; j < 8; j++ {
|
|
|
+ if result[j] == 0 {
|
|
|
+ fmt.Printf("_")
|
|
|
+ } else {
|
|
|
+ fmt.Printf("%c", result[j])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fmt.Printf("\n")
|
|
|
+ if isDone(result) {
|
|
|
+ return string(result)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|
|
|
+
|
|
|
+func main() {
|
|
|
+ if len(os.Args) != 2 {
|
|
|
+ fmt.Fprintln(os.Stderr, "Usage: PROG doorId")
|
|
|
+ } else {
|
|
|
+ doorId := os.Args[1]
|
|
|
+ ex1(doorId)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|