Created
June 9, 2019 14:05
-
-
Save pitsanujiw/1febf70a8d2a9268481ac79064af3693 to your computer and use it in GitHub Desktop.
Finding the valid order of a secret message
This file contains 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 ( | |
"github.com/gitchander/permutation" | |
"encoding/hex" | |
"crypto/sha1" | |
"crypto/hmac" | |
"strings" | |
"fmt" | |
"os" | |
) | |
func main() { | |
secretKey := "9LXAVCxcITaABNK48pAVgc4muuTNJ4enIKS5YzKyGZ" | |
finalHash := "77cc91113efbcea99ea0d5b5450f3d159694d6a2" | |
params := []string{"bb0b4a65077f7385", "09XXXXXXXX", "m8J9IpbfSBZY3Kc4AYhUMriZrZa1jqZT5EdJp9LJFcv/OAaZagEAAA==", "123456", "ABCD", "1557465220750", "mobile"} | |
byteFinalHash, _ := hex.DecodeString(finalHash) | |
prmt := permutation.New(permutation.StringSlice(params)) | |
fmt.Println("Brute-forcing...") | |
for prmt.Next() { | |
secretMessage := strings.Join(params[:], "|") | |
mac := hmac.New(sha1.New, []byte(secretKey)) | |
mac.Write([]byte(secretMessage)) | |
digest := mac.Sum(nil) | |
if (hmac.Equal(byteFinalHash, digest)) { | |
fmt.Printf("\nFound a message pattern: %s\nKey: %s\nHash: %s\n", secretMessage, secretKey, hex.EncodeToString(byteFinalHash)) | |
os.Exit(0) | |
} | |
} | |
fmt.Println("Sorry, no pattern found") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment