diff --git a/PKHeX.Core/Saves/SaveUtil.cs b/PKHeX.Core/Saves/SaveUtil.cs index a0cca1a8e..7c02f0397 100644 --- a/PKHeX.Core/Saves/SaveUtil.cs +++ b/PKHeX.Core/Saves/SaveUtil.cs @@ -608,24 +608,17 @@ public static bool GetSavesFromFolder(string folderPath, bool deep, out IEnumera /// Checksum public static ushort CRC16_CCITT(byte[] data, int start, int length) { - const ushort init = 0xFFFF; - const ushort poly = 0x1021; - - ushort crc = init; + byte top = 0xFF; + byte bot = 0xFF; int end = start + length; for (int i = start; i < end; i++) { - byte b = data[i]; - crc ^= (ushort)(b << 8); - for (int j = 0; j < 8; j++) - { - bool flag = (crc & 0x8000) > 0; - crc <<= 1; - if (flag) - crc ^= poly; - } + var x = data[i] ^ top; + x ^= (x >> 4); + top = (byte) (bot ^ (x >> 3) ^ (x << 4)); + bot = (byte) (x ^ (x << 5)); } - return crc; + return (ushort)(top << 8 | bot); } /// Calculates the CRC16-CCITT checksum over an input byte array.