Skip to content

Instantly share code, notes, and snippets.

@melkael
Created February 1, 2019 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melkael/d1ed421f6e7920901bf0e09d63711d72 to your computer and use it in GitHub Desktop.
Save melkael/d1ed421f6e7920901bf0e09d63711d72 to your computer and use it in GitHub Desktop.
func decoder(str string) string {
key := ""
best := ""
var max float32 = 0
for i := 0x00; i < 0xFF; i++ {
key = fmt.Sprintf("%c", i)
decodedHex := xorStrToChar(str, key)
decodedAscii := hexToAscii(decodedHex)
if max < rateString(decodedAscii) {
max = rateString(decodedAscii)
best = decodedAscii
}
}
if max > 1.5 {
return best
} else {
return ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment