unsigned char Convert(unsigned char ch) { unsigned char ch1,ch2; //to deal with the 0th bit and 7th bit ch1=ch&0x81; ch2=ch&0x7e;
switch(ch1) { case 0: case 0x81: break; case 1: ch=ch2|0x80; break; case 0x80: ch=ch2|0x01; break; } //to deal with the 1th bit and 6th bit ch1=ch&0x42; ch2=ch&0xbd;
switch(ch1) { case 0: case 0x42: break; case 0x40: ch=ch2|0x02; break; case 0x02: ch=ch2|0x40; break; } // to deal with the 2nd bit and 5th bit ch1=ch&0x24; ch2=ch&0xdb;
switch(ch1) { case 0: case 0x24: break; case 0x20: ch=ch2|0x04; break; case 0x04: ch=ch2|0x20; break; } // to deal with the 3rd and 4th bit ch1=ch&0x18; ch2=ch&0xe7;
switch(ch1) { case 0: case 18: break; case 0x10: ch=ch2|0x08; break; case 0x08: ch=ch2|0x10; break; } return(ch); //return converted char } void Des(void * prqp , int length) { unsigned char *pch; int i; pch = (unsigned char *)prqp; for(i=0;i<length;i++) { *pch=Convert(*pch); pch ++ ; }}
{
unsigned char ch1,ch2; //to deal with the 0th bit and 7th bit
ch1=ch&0x81;
ch2=ch&0x7e;
switch(ch1)
{
case 0:
case 0x81:
break;
case 1:
ch=ch2|0x80;
break;
case 0x80:
ch=ch2|0x01;
break;
}
//to deal with the 1th bit and 6th bit
ch1=ch&0x42;
ch2=ch&0xbd;
switch(ch1)
{
case 0:
case 0x42:
break;
case 0x40:
ch=ch2|0x02;
break;
case 0x02:
ch=ch2|0x40;
break;
} // to deal with the 2nd bit and 5th bit
ch1=ch&0x24;
ch2=ch&0xdb;
switch(ch1)
{
case 0:
case 0x24:
break;
case 0x20:
ch=ch2|0x04;
break;
case 0x04:
ch=ch2|0x20;
break;
} // to deal with the 3rd and 4th bit
ch1=ch&0x18;
ch2=ch&0xe7;
switch(ch1)
{
case 0:
case 18:
break;
case 0x10:
ch=ch2|0x08;
break;
case 0x08:
ch=ch2|0x10;
break;
}
return(ch); //return converted char
}
void Des(void * prqp , int length)
{ unsigned char *pch;
int i;
pch = (unsigned char *)prqp; for(i=0;i<length;i++)
{
*pch=Convert(*pch);
pch ++ ;
}}