This commit is contained in:
TheJoKlLa
2020-10-06 15:59:53 +02:00
parent d601e9afb3
commit f5dffcec5b
5 changed files with 338 additions and 67 deletions

44
NFC/Crypto/CRC32.cs Normal file
View File

@ -0,0 +1,44 @@
using System;
namespace NFC.Crypto
{
public class CRC32
{
public byte[] Calculate(byte[] data)
{
UInt32 crc32 = 0xFFFFFFFF;
crc32 = Calculate(data, crc32);
return BitConverter.GetBytes(crc32);
}
public byte[] Calculate(byte[] cmd, byte[] data)
{
UInt32 crc32 = 0xFFFFFFFF;
crc32 = Calculate(cmd, crc32);
crc32 = Calculate(data, crc32);
return BitConverter.GetBytes(crc32);
}
public UInt32 Calculate(byte[] data, UInt32 crc32)
{
for (int i = 0; i < data.Length; i++)
{
crc32 ^= data[i];
for (int b = 0; b < 8; b++)
{
bool b_Bit = (crc32 & 0x01) > 0;
crc32 >>= 1;
if (b_Bit)
{
crc32 ^= 0xEDB88320;
}
}
}
return crc32;
}
}
}