Skip to content

Instantly share code, notes, and snippets.

@awreece
Created June 10, 2013 00:59
Show Gist options
  • Save awreece/5745925 to your computer and use it in GitHub Desktop.
Save awreece/5745925 to your computer and use it in GitHub Desktop.
package main
import "crypto/aes"
import "fmt"
import "encoding/hex"
var start = []byte("AES-256 ECB mode twice, two keys")
var end = []byte("\x4c\x76\xe9\x07\x86\xc4\xf3\x64\x6a\xdf\x99\x21\x7a\x64\xd0\xd7\x49\xed\xc5\x9f\x2c\x7f\xbb\x36\x58\xaf\x04\xaf\x07\x1d\x0c\x47")
var reverse = make(map[string][32]byte)
func main() {
var keys[1<<24][32]byte
for i := 0; i < 1<<24; i++ {
keys[i][29] = byte(i & 0xff);
keys[i][30] = byte((i >> 8) & 0xff);
keys[i][31] = byte((i >> 16) & 0xff);
}
for i := 0; i < 1<<24; i++ {
b, _ := aes.NewCipher(keys[i][:])
dest := make([]byte, 16)
b.Encrypt(dest, start[:16])
reverse[hex.EncodeToString(dest)] = keys[i]
}
fmt.Println("Encoded all the things")
for i := 0; i < 1<<24; i++ {
b, _ := aes.NewCipher(keys[i][:])
dest := make([]byte, 16)
b.Decrypt(dest, end[:16])
if v, ok := reverse[hex.EncodeToString(dest)]; ok {
fmt.Println(hex.EncodeToString(v[:]))
fmt.Println(hex.EncodeToString(keys[i][:]))
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment