In C:

unsigned char BitTwiddle(unsigned char input)
{
     //this function scrambles the bits of the input
     //change the hard-coded bitwise ors and ands for desired output
     //this example takes 2->5, 0->7, 1->3, 3->4, 4->0, 5->2, 6->1, 7->6
     return ( ((input&0x04)?0x20:0x00)|
              ((input&0x01)?0x80:0x00)|
              ((input&0x02)?0x08:0x00)|
              ((input&0x08)?0x10:0x00)|
              ((input&0x10)?0x01:0x00)|
              ((input&0x20)?0x04:0x00)|
              ((input&0x40)?0x02:0x00)|
              ((input&0x80)?0x40:0x00));
}