编辑代码

package main
import (
    "encoding/hex"
    "fmt"
    "unicode/utf16"
    "encoding/binary"
    "bytes"
)
func IntToBytes(n int16) []byte {
  bytesBuffer := bytes.NewBuffer([]byte{})
  binary.Write(bytesBuffer, binary.BigEndian, n)
  return bytesBuffer.Bytes()
}
func BytesCombine(pBytes ...[]byte) []byte {
    return bytes.Join(pBytes, []byte(""))
}
// UTF16ToUTF8 将 UTF-16 字节数组转换为 UTF-8 字节数组
func UTF16ToUTF8(utf16Bytes []byte) ([]byte) {
    // 确保字节数组的长度是偶数
    if len(utf16Bytes)%2 != 0 {
        return nil
    }
    // 将 UTF-16 字节数组转换为 uint16 切片
    utf16Slice := make([]uint16, len(utf16Bytes)/2)
    for i := 0; i < len(utf16Bytes); i += 2 {
        utf16Slice[i/2] = binary.BigEndian.Uint16(utf16Bytes[i : i+2])
    }
    // 将 UTF-16 切片转换为 UTF-8 字节数组
    utf8Runes := utf16.Decode(utf16Slice)
    utf8Bytes := []byte(string(utf8Runes))
    return utf8Bytes
}

// UTF16CharToUTF8 将单个 UTF-16 字节转换为 UTF-8 字节数组
func UTF16CharToUTF8(utf16Char uint16) []byte {
    // 将 UTF-16 字符转换为 UTF-8 字符串,然后返回其字节数组
    return []byte(string(utf16Char))
}
func main () {
    cat, _ := hex.DecodeString("44D8B7339C9CE62B014E212A62936ABE589651C103D87C506D7AC9B5DA2425E7")
    maa, _ := hex.DecodeString("8AFDB7D6E9E509662B5961CEAF78C8102B71C3C16734189F7846CCE6B4C574DB")
    dog, _ := hex.DecodeString("29a15733fcad92b82a3c065feee382c635e6a0565aa0bb868294636a631ed74e")
    //rat, _ := hex.DecodeString("7df66eed40eb913aad67b96bf634268294d84551410efacab8ea494b15ccd31d")
    var res string =""
    for i := 0; i < 32; i++ {
      tmp:=int16(cat[i]^maa[i]^dog[i])
      if tmp>127 {
          tmp=tmp-256
      }

      if tmp<0 {
          tmp=int16(int32(65536)+int32(tmp))
      }
      switch{
          case (tmp<256) && (tmp!=0):
            res=res+hex.EncodeToString(UTF16ToUTF8(IntToBytes(tmp)))
          case tmp==0:
            res=res+"00"
      } 
   }
   fmt.Println(res)   
}