Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions net/packet_process_assist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,28 @@ bool checksum(const char* src_data, uint16& check_ret) {
return ret;
}

extern "C"{
//加密 key
unsigned int key = 1234567890; // NOLINT //key
unsigned int key[5] = {1,2,3,4,5}; // NOLINT //key
unsigned int GetKey() {
return key;
return key[0]*10000+key[1]*1000+key[2]*100+key[3]*10+0;
}

void SetKey(unsigned int k) {
key = k;
key[0] = k/10000;
key[1] = (k%10000)/1000;
key[2] = (k%1000)/100;
key[3] = (k%100)/10;
}

unsigned int CreateKey() {
key = 0 + rand() % (99999 - 0 + 1);
return key;
unsigned int randKey = 0 + rand() % (99999 - 0 + 1);
key[0] = randKey/10000;
key[1] = (randKey%10000)/1000;
key[2] = (randKey%1000)/100;
key[3] = (randKey%100)/10;
return key[0]*10000+key[1]*1000+key[2]*100+key[3]*10+0;
}
}

// jiami
Expand Down Expand Up @@ -109,7 +118,7 @@ char* str_en_8byte(char *clearmsg, int len, int rounds, int& len1) {
for (i = 0; i < len1; i += 8) {
y1 = (unsigned int *)&en[i]; // NOLINT
y2 = (unsigned int *)&en[i+4]; // NOLINT
encrypt(y1, y2, &key, rounds);
encrypt(y1, y2, key, rounds);
}
en[len1] = '\0';
return en;
Expand All @@ -127,7 +136,7 @@ char* str_de_8byte(char *encryptedmsg, int len, int rounds) {
for (i = 0; i < len; i += 8) {
y1 = (unsigned int *)&de[i]; // NOLINT
y2 = (unsigned int *)&de[i+4]; // NOLINT
decrypt(y1, y2, &key, rounds);
decrypt(y1, y2, key, rounds);
}
*(de+len) = '\0';
return de;
Expand Down
4 changes: 2 additions & 2 deletions net/packet_process_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <list>
#include <string>


extern "C"{
//明文->密文
bool PacketStream(const void *in_stream, int32 in_stream_length,
void **out_stream, int32* out_stream_length) {
Expand Down Expand Up @@ -207,4 +207,4 @@ bool UnpackStream(const void *in_stream, int32 in_stream_length,
}
return true;
}

}
4 changes: 2 additions & 2 deletions net/packet_process_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@


//明文->密文
bool PacketStream(const void *in_stream, int32 in_stream_length,
extern "C" bool PacketStream(const void *in_stream, int32 in_stream_length,
void **out_stream, int32* out_stream_length);

//密文->明文
bool UnpackStream(const void *in_stream, int32 in_stream_length,
extern "C" bool UnpackStream(const void *in_stream, int32 in_stream_length,
void **out_stream, int32* out_stream_length);
#endif /* SWP_PUB_NET_PACKET_PROCESS_FUNCTION_H_ */