I am having a slight problem implementing this code. What I need to do is take a list of 16 unsigned characters and permute the bits according to IPTable. 0 in IPTable refers to bit 0, 1 refers to bit 1, etc. Here is my code which isn't working.
unsigned char IPTable[128] = {0, 32, 64, 96, 1, 33, 65, 97, 2, 34, 66, 98, 3, 35, 67, 99, 4, 36, 68, 100, 5, 37, 69, 101, 6, 38, 70, 102, 7, 39, 71, 103, 8, 40, 72, 104, 9, 41, 73, 105, 10, 42, 74, 106, 11, 43, 75, 107, 12, 44, 76, 108, 13, 45, 77, 109, 14, 46, 78, 110, 15, 47, 79, 111, 16, 48, 80, 112, 17, 49, 81, 113, 18, 50, 82, 114, 19, 51, 83, 115, 20, 52, 84, 116, 21, 53, 85, 117, 22, 54, 86, 118, 23, 55, 87, 119, 24, 56, 88, 120, 25, 57, 89, 121, 26, 58, 90, 122, 27, 59, 91, 123, 28, 60, 92, 124, 29, 61, 93, 125, 30, 62, 94, 126, 31, 63, 95, 127};
void IP(unsigned char * input, unsigned char * output)
{
unsigned char i;
for (i = 0; i < 128; i++)
{
output[i / 8] ^= (128 >> (IPTable[i] % 8)) & input[IPTable[i]];
}
Thanks for the help. By the way this code definitely won't work if output isn't set to all zeroes, I already know that and that isn't the error.