From d0c68f55e448834279bd80663e1f2fe70a144a8b Mon Sep 17 00:00:00 2001 From: Joon Park <5825014+jpark730@users.noreply.github.com> Date: Fri, 6 Mar 2020 22:47:51 -0500 Subject: [PATCH] . --- Source/xgmsv/test_server/mmo_server.cpp | 7 ++- Source/xgmsv/test_server/xg_crypto.h | 84 ++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/Source/xgmsv/test_server/mmo_server.cpp b/Source/xgmsv/test_server/mmo_server.cpp index d4c21ce..93077ba 100644 --- a/Source/xgmsv/test_server/mmo_server.cpp +++ b/Source/xgmsv/test_server/mmo_server.cpp @@ -93,7 +93,12 @@ namespace mmo_server }); //char packet4[] = "MLVlll6KdKyJmGKKII5pnmuNyMUp31qWQ7QqzcfGII5pnmuNN8X5wcMqzCuyJMAX2"; - //crossgate::decrypt_message(packet4); + char packet[] = "CmMMlxipiG42g1E"; + //crossgate::decrypt_message(packet, sizeof(packet)); + + char packet2[] = "Echo nr "; + + crossgate::encrypt_message(packet2, sizeof(packet2)); core::async_every(1000ms, []() { diff --git a/Source/xgmsv/test_server/xg_crypto.h b/Source/xgmsv/test_server/xg_crypto.h index f5a459e..a95515f 100644 --- a/Source/xgmsv/test_server/xg_crypto.h +++ b/Source/xgmsv/test_server/xg_crypto.h @@ -99,7 +99,7 @@ namespace server return stage_3; } - void decrypt_message(char*& data, uint32& size) + void decrypt_message(char* data, uint32 size) { // 6 bit to 8 bit string size = util_64to256(data, data, mapping_table); @@ -131,9 +131,89 @@ namespace server } - void encrypt_message(char*& data, uint32& size) + uint8 apply_conditional_bit_reverse(char* dst, const char* src, size_t length) { + char sum = 0; + // conditional bit reverse, seed = 4595 + for (int i = 0; i < length; i++) + { + sum += src[i]; + if (SEED % 7 == i % 5 || SEED % 2 == i % 2) + { + dst[i] = ~src[i]; + } + uint64 result = length; + } + + return sum; + } + + int apply_salt(char* dst, const char* src, size_t length, uint8 sum) + { + // conditional salt + int seed = SEED % length; //38 when message_size = 49 + for (int i = 0; i < (length + 1); i++) + { + if (i < seed) + { + dst[i] = src[i] + sum * (i * i % 3); + } + + if (i == seed) + { + dst[i] = sum; + } + + if (i > seed) + { + dst[i] = src[i - 1] + sum * (i * i % 7); + } + + //uint64 result = out_int; + } + + return 0; + } + + int util_256to64(char *dst, char *src, size_t length) + { + unsigned int dw, dwcounter, i; + + if (!dst || !src || !mapping_table) return 0; + dw = 0; + dwcounter = 0; + for (i = 0; i < length; i++) { + dw = (((unsigned int)src[i] & 0xff) << ((i % 3) * 2)) | dw; + dst[dwcounter++] = mapping_table[dw & 0x3f]; + dw = (dw >> 6); + if (i % 3 == 2) { + dst[dwcounter++] = mapping_table[dw & 0x3f]; + dw = 0; + } + } + if (dw) dst[dwcounter++] = mapping_table[dw]; + dst[dwcounter] = '\0'; + return dwcounter; + } + + + void encrypt_message(char* data, uint32 size) + { + memmove(data + 1, data, size); + size++; + + data[0] = 0; + + + uint8 sum = apply_conditional_bit_reverse(data, data, size); + apply_salt(data, data, size, sum); + + data[0] = size + 1; + + + char result[256]; + util_256to64(result, data, size); } } } \ No newline at end of file