mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-12 23:14:36 +01:00
simplify EntranceServer crypto
This commit is contained in:
@@ -12,45 +12,40 @@ var (
|
||||
|
||||
// CalcSum32 calculates the custom MHF "sum32" checksum of the given data.
|
||||
func CalcSum32(data []byte) uint32 {
|
||||
tableIdx0 := int(len(data) & 0xFF)
|
||||
tableIdx1 := int(data[len(data)>>1] & 0xFF)
|
||||
|
||||
tableIdx0 := (len(data) + 1) & 0xFF
|
||||
tableIdx1 := int((data[len(data)>>1] + 1) & 0xFF)
|
||||
out := make([]byte, 4)
|
||||
for i := 0; i < len(data); i++ {
|
||||
tableIdx0++
|
||||
tableIdx1++
|
||||
|
||||
tmp := byte((_sum32Table1[tableIdx1%9] ^ _sum32Table0[tableIdx0%7]) ^ data[i])
|
||||
out[i&3] = (out[i&3] + tmp) & 0xFF
|
||||
key := _sum32Table0[(tableIdx0+i)%7] ^ _sum32Table1[(tableIdx1+i)%9]
|
||||
out[i&3] = (out[i&3] + (data[i] ^ key)) & 0xFF
|
||||
}
|
||||
|
||||
return binary.BigEndian.Uint32(out)
|
||||
}
|
||||
|
||||
func rotate(k *uint32) {
|
||||
*k = uint32(((54323 * uint(*k)) + 1) & 0xFFFFFFFF)
|
||||
}
|
||||
|
||||
// EncryptBin8 encrypts the given data using MHF's "binary8" encryption.
|
||||
func EncryptBin8(data []byte, key byte) []byte {
|
||||
curKey := uint32(((54323 * uint(key)) + 1) & 0xFFFFFFFF)
|
||||
|
||||
_key := uint32(key)
|
||||
var output []byte
|
||||
for i := 0; i < len(data); i++ {
|
||||
tmp := (_bin8Key[i&7] ^ byte((curKey>>13)&0xFF))
|
||||
rotate(&_key)
|
||||
tmp := _bin8Key[i&7] ^ byte((_key>>13)&0xFF)
|
||||
output = append(output, data[i]^tmp)
|
||||
curKey = uint32(((54323 * uint(curKey)) + 1) & 0xFFFFFFFF)
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
// DecryptBin8 decrypts the given MHF "binary8" data.
|
||||
func DecryptBin8(data []byte, key byte) []byte {
|
||||
curKey := uint32(((54323 * uint(key)) + 1) & 0xFFFFFFFF)
|
||||
|
||||
_key := uint32(key)
|
||||
var output []byte
|
||||
for i := 0; i < len(data); i++ {
|
||||
tmp := (data[i] ^ byte((curKey>>13)&0xFF))
|
||||
rotate(&_key)
|
||||
tmp := data[i] ^ byte((_key>>13)&0xFF)
|
||||
output = append(output, tmp^_bin8Key[i&7])
|
||||
curKey = uint32(((54323 * uint(curKey)) + 1) & 0xFFFFFFFF)
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user