Skip to content

Instantly share code, notes, and snippets.

@nemith
Created April 30, 2015 02:49
Show Gist options
  • Select an option

  • Save nemith/2064044750421572282b to your computer and use it in GitHub Desktop.

Select an option

Save nemith/2064044750421572282b to your computer and use it in GitHub Desktop.
package tictac
import (
"crypto/md5"
"encoding/binary"
)
func createHash(version, seq uint8, sessionId uint32, key, lastHash []byte) []byte {
h := md5.New()
binary.Write(h, binary.BigEndian, sessionId)
h.Write(key)
binary.Write(h, binary.BigEndian, version)
binary.Write(h, binary.BigEndian, seq)
h.Write(lastHash)
return h.Sum(nil)
}
func crypt(data, key []byte, version, seq uint8, sessionId uint32) {
var lastHash []byte
for i := 0; i < len(data); i += 16 {
hash := createHash(version, seq, sessionId, key, lastHash)
lastHash = hash[:]
for j := 0; j < len(hash); j++ {
if i+j < len(data) {
data[i+j] ^= hash[j]
} else {
break
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment