Is it possible to create a specific permutation of an array with a macro in C?
i.e. If I have an X array with elements:
0 1 2 3 4 5 x = ["0","1","1","0","1","0"]
I thought there might be a foo macro for something like this:
#define S_2Permute(x) = [x[5], x[3], x[4], x[2], x[1]]
where I redefine the order of the array, so the element in starting position 5 is now at position 0.
Any ideas?
EXAMPLE OF USE
I am starting to create an implementation of the DES encryption algorithm. DES requires several permutations / extensions, in which I will have to reorder all elements of the array, sometimes shrinking the array and sometimes expanding it. I was hoping to just define a macro to move arrays for me.
EDIT2
Well, in DES, the first step is something called an initial permutation. Therefore, initially I have a 64-bit key, which for this example can be 0-15 hex:
0123456789ABCDEF
which expands to:
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
IP (initial permutation) will rearrange this line so that each element of the array is in a new position:
IP = 58 50 42 34 26 18 10 2 60 52 44 36 28 20 12 4 62 54 46 38 30 22 14 6 64 56 48 40 32 24 16 8 57 49 41 33 25 17 9 1 59 51 43 35 27 19 11 3 61 53 45 37 29 21 13 5 63 55 47 39 31 23 15 7
Thus, the new 1st element in the bit string will be the 58th element (bit) from the original bit string.
So, I would have all these bits stored in an array of characters:
x = [0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,0,1,0,0,0,1,0,1,0,1,1,0,0, 1,1,1,1,0,0,0,1,0,0,1,1,0,1,0,1,0,1,1,1,1,0,0,1,1,0,1,1,1,1,0,1,1,1,1]
and then just call
IP_PERMUTE(x);
And macro magic will move all the bits to the new right positions.