# What is this CRC32 algorithm (written in C), and how can it be written in Java or Python?

I've been trying to convert this CRC32 algorithm to Java or Python, but I haven't been successful, I believe it's because I'm not familiar enough with c.

Note that I believe `DAT_804818d0` is the seed, which I still haven't found.

This was my naive attempt at converting the below code to Java (I suspect I've made numerous mistakes): https://pastebin.com/6XnxqaBp

``````uint zz_801744d0_(byte *param_1,int param_2)

{
byte *pbVar1;
byte *pbVar2;
byte *pbVar3;
byte *pbVar4;
byte *pbVar5;
byte *pbVar6;
byte bVar7;
bool bVar8;
int iVar9;
int iVar10;
uint uVar11;
uint uVar12;

//The code in this if statement appears to handle the first 4 bytes in a special manner
if (3 < param_2) {
pbVar1 = param_1 + 1;
param_2 = param_2 + -4;
pbVar2 = param_1 + 2;
bVar7 = *param_1;
pbVar3 = param_1 + 3;
param_1 = param_1 + 4;
uVar11 = ~((uint)bVar7 << 0x18 | (uint)*pbVar1 << 0x10 | (uint)*pbVar2 << 8 | (uint)*pbVar3);
}

iVar10 = 0;
if (0 < param_2) { //If the data was 4 bytes in size or less, we just return ~uVar11
if (8 < param_2) { //If the data was 12 bytes or more, the rest are handled in chunks of 8 bytes
bVar8 = false;
if ((-1 < param_2) && (param_2 < 0x7fffffff)) {
bVar8 = true;
}
if ((bVar8) && (uVar12 = param_2 - 1U >> 3, 0 < param_2 + -8)) {
do {
iVar10 = iVar10 + 8;
uVar11 = (uVar11 << 8 | (uint)*param_1) ^
*(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
pbVar1 = param_1 + 2;
pbVar2 = param_1 + 3;
pbVar3 = param_1 + 4;
uVar11 = (uVar11 << 8 | (uint)param_1[1]) ^
*(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
pbVar4 = param_1 + 5;
pbVar5 = param_1 + 6;
pbVar6 = param_1 + 7;
param_1 = param_1 + 8;
uVar11 = (uVar11 << 8 | (uint)*pbVar1) ^
*(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
uVar11 = (uVar11 << 8 | (uint)*pbVar2) ^
*(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
uVar11 = (uVar11 << 8 | (uint)*pbVar3) ^
*(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
uVar11 = (uVar11 << 8 | (uint)*pbVar4) ^
*(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
uVar11 = (uVar11 << 8 | (uint)*pbVar5) ^
*(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
uVar11 = (uVar11 << 8 | (uint)*pbVar6) ^
*(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
uVar12 = uVar12 - 1;
} while (uVar12 != 0);
}
}
iVar9 = param_2 - iVar10;
if (iVar10 < param_2) { //Any remaining bytes are handled one at a time.
do {
bVar7 = *param_1;
param_1 = param_1 + 1;
uVar11 = (uVar11 << 8 | (uint)bVar7) ^ *(uint *)(&DAT_804818d0 + (uVar11 >> 0x16 & 0x3fc));
iVar9 = iVar9 + -1;
} while (iVar9 != 0);
}
}
return ~uVar11;
}
``````
• Do you need to use it in Java/Python or do you really need a native implementation? because often it is easier to include the executable/library the function is implemented in into a a custom library that has an interface to Java or Python so you can simple use the original implementation. Jan 21 at 12:11
• I believe I need a non-native implementation. The binary was compiled for Wii architecture. I'm not aware of anything (other than emulation) which allows a PC to run portions of a Wii game binary. Jan 21 at 13:26