我编写加密\解密系统(原型)。该系统有 188 字节的数据包。并加扰:
加密(Python):
#key = 40
packet[4]+packet[40:]+packet[4:40]
解密(C):
//in_buffer - main char* massive
//offs - offset of packet (length 188)
//key - int for separator (40 in example before)
void encryption(byte* in_buffer, int offs, int key)
{
byte temp[188];
int i;
//write packet[4:40] to temp
for(i = 4;i < key; i++)
{
temp[i] = in_buffer[offs+i];
}
//write packet[40:] to top
for(i = 4;i < 188 - key+4; i++)
{
in_buffer[offs+i] = in_buffer[offs+i+key-4];
}
//write packet[4:40] of temp to in_buffer[152:]
for(i = 4;i < key; i++)
{
in_buffer[offs+i+188-key] = temp[i];
}
}
它适用于 key = 96,但不适用于任何其他键!为什么?