I am trying to understand a block of code for calculating a CRC in the hopes of improving / modifying it, To me it seems odd that each bytes while loop spins away 255 times?
Var17 = 0x05; //DATA for calculation
Var18 = 0x00;
Var19 = 0x00;
Var20 = 0x00;
Var14 = 0xFFFF; //CRC initial value
Var15 = 0; //counter
Var16 = 0;
While(Var15 != 255)
{
Var15 = Var15 + 1;
Var14 = Var14 ^ (Var17);
While(Var16 != 8)
{
Var16 = Var16 + 1;
if((Var14 & 0x0001) != 0) {Var14 = (Var14 >> 1) ^ 0x8408; }
else {Var14 = (Var14 >> 1); }
}
}
Var14 = Var14 & 65535;
Var15 = 0; //counter
Var16 = 0;
While(Var15 != 255)
{
Var15 = Var15 + 1;
Var14 = Var14 ^ (Var18);
While(Var16 != 8)
{
Var16 = Var16 + 1;
if((Var14 & 0x0001) != 0) {Var14 = (Var14 >> 1) ^ 0x8408; }
else {Var14 = (Var14 >> 1); }
}
}
Var14 = Var14 & 65535;
Var15 = 0; //counter
Var16 = 0;
While(Var15 != 255)
{
Var15 = Var15 + 1;
Var14 = Var14 ^ (Var19);
While(Var16 != 8)
{
Var16 = Var16 + 1;
if((Var14 & 0x0001) != 0) {Var14 = (Var14 >> 1) ^ 0x8408; }
else {Var14 = (Var14 >> 1); }
}
}
Var14 = Var14 & 65535;
Var15 = 0; //counter
Var16 = 0;
While(Var15 != 255)
{
Var15 = Var15 + 1;
Var14 = Var14 ^ (Var20);
While(Var16 != 8)
{
Var16 = Var16 + 1;
if((Var14 & 0x0001) != 0) {Var14 = (Var14 >> 1) ^ 0x8408; }
else {Var14 = (Var14 >> 1); }
}
}
Var14 = Var14 & 65535;
input data is 05000000, I've substituted it in the code to try and make things clearer, expected result is 6D76 or 766D, (do not know the eadianess) If i could please get some help understanding just what it is doing, or suggestions for making it run better, it would be appreciated, only thing to note is a do not think the script language supports look up tables,
I've been shown in the past that the same CRC can be calacutled by the settings below, but this really confuses me, as with both cases i haven't been able to replicate its output on any online calculator:
CRC 16 Bits
Initial: FFFF
Poly: 1021
Xor In/Out: 0
Reflect in/ Out: True,