This repository has been archived on 2020-03-29. You can view files and clone it, but cannot push or open issues or pull requests.
sampy_archive/sampy/helpers/checksumHelper.py

25 lines
642 B
Python
Raw Normal View History

2020-03-29 18:45:38 +02:00
from ..network.enums import types as TYPE
2019-12-14 20:08:34 +01:00
# TODO: Single function if Object's state is not needed
class CheckSum:
def __init__(self):
self.clear()
def clear(self):
self.sum = 0
self.r = 55665
self.c1 = 52845
self.c2 = 22719
def add(self, byteArray):
[self._add(b) for b in byteArray]
def _add(self, byte):
cipher = byte ^ (self.r >> 8)
cipher &= TYPE.MAX_UCHAR # [BYTE MAGIC]
self.r = (cipher + self.r) * self.c1 + self.c2
self.r &= TYPE.MAX_USHORT # [BYTE MAGIC]
self.sum += cipher
def get(self):
return self.sum