Created
April 30, 2015 02:49
-
-
Save nemith/2064044750421572282b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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