// EncType1_Decode_Test.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "raw.h"

#define PACKET_OVERHEAD 62

unsigned char *secureKey = "NRLRBD"; /* challenge from server (randomly generated) */
unsigned char *validateKey = "V/yOzx8A"; /* response from client to server */
unsigned char *gameKey = "d4kZca"; /* gamespy2 */

unsigned char *enctype1_decoder(unsigned char *id, unsigned char *, int *);
int enctype1_wrapper(unsigned char *key, unsigned char *data, int size);
extern int enctypex_decoder_convert_to_ipport(unsigned char *data, int datalen, unsigned char *out, unsigned char *infobuff, int infobuff_size, int infobuff_offset);


static const unsigned char enctype1_data[] = /* pre-built */
"\x01\xba\xfa\xb2\x51\x00\x54\x80\x75\x16\x8e\x8e\x02\x08\x36\xa5"
"\x2d\x05\x0d\x16\x52\x07\xb4\x22\x8c\xe9\x09\xd6\xb9\x26\x00\x04"
"\x06\x05\x00\x13\x18\xc4\x1e\x5b\x1d\x76\x74\xfc\x50\x51\x06\x16"
"\x00\x51\x28\x00\x04\x0a\x29\x78\x51\x00\x01\x11\x52\x16\x06\x4a"
"\x20\x84\x01\xa2\x1e\x16\x47\x16\x32\x51\x9a\xc4\x03\x2a\x73\xe1"
"\x2d\x4f\x18\x4b\x93\x4c\x0f\x39\x0a\x00\x04\xc0\x12\x0c\x9a\x5e"
"\x02\xb3\x18\xb8\x07\x0c\xcd\x21\x05\xc0\xa9\x41\x43\x04\x3c\x52"
"\x75\xec\x98\x80\x1d\x08\x02\x1d\x58\x84\x01\x4e\x3b\x6a\x53\x7a"
"\x55\x56\x57\x1e\x7f\xec\xb8\xad\x00\x70\x1f\x82\xd8\xfc\x97\x8b"
"\xf0\x83\xfe\x0e\x76\x03\xbe\x39\x29\x77\x30\xe0\x2b\xff\xb7\x9e"
"\x01\x04\xf8\x01\x0e\xe8\x53\xff\x94\x0c\xb2\x45\x9e\x0a\xc7\x06"
"\x18\x01\x64\xb0\x03\x98\x01\xeb\x02\xb0\x01\xb4\x12\x49\x07\x1f"
"\x5f\x5e\x5d\xa0\x4f\x5b\xa0\x5a\x59\x58\xcf\x52\x54\xd0\xb8\x34"
"\x02\xfc\x0e\x42\x29\xb8\xda\x00\xba\xb1\xf0\x12\xfd\x23\xae\xb6"
"\x45\xa9\xbb\x06\xb8\x88\x14\x24\xa9\x00\x14\xcb\x24\x12\xae\xcc"
"\x57\x56\xee\xfd\x08\x30\xd9\xfd\x8b\x3e\x0a\x84\x46\xfa\x77\xb8";

static unsigned char gsvalfunc(int reg)
{
    if (reg < 26)
        return(reg + 'A');
    if (reg < 52)
        return(reg + 'G');
    if (reg < 62)
        return(reg - 4);
    if (reg == 62)
        return('+');
    if (reg == 63)
        return('/');

    return(0);
}

unsigned char *gsseckey(unsigned char *dst, unsigned char *src, unsigned char *key, int enctype)
{
    int i, size, keysz;
    unsigned char enctmp[256], tmp[66], x, y, z, a, b, *p;

    if (!dst)
    {
        dst = (unsigned char *)malloc(89);
        if (!dst)
            return(NULL);
    }
    size = strlen((const char *)src);
    if ((size < 1) || (size > 65))
    {
        dst[0] = 0;
        return(dst);
    }
    keysz = strlen((const char *)key);

    for (i = 0; i < 256; i++)
    {
        enctmp[i] = i;
    }

    a = 0;
    for (i = 0; i < 256; i++)
    {
        a += enctmp[i] + key[i % keysz];
        x = enctmp[a];
        enctmp[a] = enctmp[i];
        enctmp[i] = x;
    }

    a = 0;
    b = 0;
    for (i = 0; src[i]; i++)
    {
        a += src[i] + 1;
        x = enctmp[a];
        b += x;
        y = enctmp[b];
        enctmp[b] = x;
        enctmp[a] = y;
        tmp[i] = src[i] ^ enctmp[(x + y) & 0xff];
    }
    for (size = i; size % 3; size++)
    {
        tmp[size] = 0;
    }

    if (enctype == 1)
    {
        for (i = 0; i < size; i++)
        {
            tmp[i] = enctype1_data[tmp[i]];
        }
    }
    else if (enctype == 2)
    {
        for (i = 0; i < size; i++)
        {
            tmp[i] ^= key[i % keysz];
        }
    }

    p = dst;
    for (i = 0; i < size; i += 3)
    {
        x = tmp[i];
        y = tmp[i + 1];
        z = tmp[i + 2];
        *p++ = gsvalfunc(x >> 2);
        *p++ = gsvalfunc(((x & 3) << 4) | (y >> 4));
        *p++ = gsvalfunc(((y & 15) << 2) | (z >> 6));
        *p++ = gsvalfunc(z & 63);
    }
    *p = 0;

    return(dst);
}


int main()
{
    unsigned char *p = (unsigned char *)calloc(1,
        sizeof(unsigned char) *
        (sizeof(pkt11) + sizeof(pkt12) + sizeof(pkt14) + sizeof(pkt16) + sizeof(pkt17) + sizeof(pkt19) + sizeof(pkt20) +
         sizeof(pkt22) + sizeof(pkt23) + sizeof(pkt25) + sizeof(pkt26) + sizeof(pkt28) + sizeof(pkt29) + sizeof(pkt31) +
         sizeof(pkt31) + sizeof(pkt32) + sizeof(pkt34) + sizeof(pkt35) + sizeof(pkt35) + sizeof(pkt37) + sizeof(pkt38) +
         sizeof(pkt40) + sizeof(pkt41) + sizeof(pkt43) + sizeof(pkt44) + sizeof(pkt46) + sizeof(pkt47) + sizeof(pkt49) +
         sizeof(pkt50) + sizeof(pkt52) + sizeof(pkt53) + sizeof(pkt55) + sizeof(pkt56) + sizeof(pkt58) + sizeof(pkt59) +
         sizeof(pkt61) + sizeof(pkt62) + sizeof(pkt64) + sizeof(pkt65) + sizeof(pkt67) + sizeof(pkt68) + sizeof(pkt70) +
         sizeof(pkt71) + sizeof(pkt73) + sizeof(pkt74) + sizeof(pkt76) + sizeof(pkt77) + sizeof(pkt79) + sizeof(pkt80) +
         sizeof(pkt82) + sizeof(pkt83) + sizeof(pkt85) + sizeof(pkt86) + sizeof(pkt88) + sizeof(pkt89) + sizeof(pkt91) +
         sizeof(pkt92) + sizeof(pkt94) + sizeof(pkt95) + sizeof(pkt97) + sizeof(pkt98) + sizeof(pkt100) + sizeof(pkt101) +
         sizeof(pkt103) + sizeof(pkt104) + sizeof(pkt106) + sizeof(pkt107) + sizeof(pkt109) + sizeof(pkt110) + sizeof(pkt112) +
         sizeof(pkt113) + sizeof(pkt115) + sizeof(pkt116) + sizeof(pkt118) + sizeof(pkt119) + sizeof(pkt121) + sizeof(pkt122) +
         sizeof(pkt124) + sizeof(pkt125) + sizeof(pkt127) + sizeof(pkt128) + sizeof(pkt130) + sizeof(pkt131) + sizeof(pkt133) +
         sizeof(pkt134) + sizeof(pkt136) + sizeof(pkt137) + sizeof(pkt139) + sizeof(pkt140) + sizeof(pkt142) + sizeof(pkt143) +
         sizeof(pkt145) + sizeof(pkt146) + sizeof(pkt148) + sizeof(pkt149) + sizeof(pkt151) + sizeof(pkt152) + sizeof(pkt154) +
         sizeof(pkt155) + sizeof(pkt157) + sizeof(pkt158) + sizeof(pkt160) + sizeof(pkt161) + sizeof(pkt163) + sizeof(pkt164) +
         sizeof(pkt166) + sizeof(pkt167) + sizeof(pkt169) + sizeof(pkt170) + sizeof(pkt172) + sizeof(pkt173) + sizeof(pkt175) +
         sizeof(pkt176) + sizeof(pkt178) + sizeof(pkt179) + sizeof(pkt181) + sizeof(pkt182) + sizeof(pkt184))
    );

    int packetSize = 160858;
    int len, i;
    char *decodedKey = NULL;

    decodedKey = gsseckey(NULL, secureKey, "d4kZca", 1);
    if (!strcmp(decodedKey, validateKey))
    {
        printf("Keys match.\n");
    }

    len = sizeof(pkt11) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt11 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt12) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt12 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt14) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt14 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt16) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt16 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt17) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt17 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt19) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt19 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt20) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt20 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt22) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt22 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt23) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt23 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt25) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt25 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt26) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt26 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt28) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt28 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt29) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt29 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt31) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt31 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt32) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt32 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt34) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt34 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt35) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt35 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt37) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt37 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt38) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt38 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt40) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt40 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt41) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt41 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt43) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt43 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt44) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt44 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt46) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt46 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt47) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt47 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt49) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt49 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt50) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt50 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt52) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt52 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt53) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt53 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt55) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt55 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt56) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt56 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt58) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt58 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt59) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt59 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt61) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt61 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt62) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt62 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt64) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt64 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt65) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt65 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt67) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt67 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt68) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt68 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt70) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt70 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt71) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt71 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt73) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt73 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt74) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt74 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt76) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt76 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt77) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt77 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt79) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt79 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt80) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt80 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt82) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt82 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt83) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt83 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt85) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt85 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt86) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt86 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt88) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt88 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt89) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt89 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt91) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt91 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt92) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt92 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt94) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt94 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt95) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt95 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt97) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt97 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt98) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt98 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt100) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt100 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt101) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt101 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt103) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt103 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt104) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt104 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt106) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt106 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt107) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt107 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt109) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt109 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt110) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt110 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt112) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt112 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt113) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt113 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt115) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt115 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt116) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt116 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt118) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt118 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt119) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt119 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt121) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt121 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt122) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt122 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt124) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt124 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt125) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt125 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt127) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt127 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt128) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt128 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt130) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt130 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt131) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt131 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt133) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt133 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt134) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt134 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt136) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt136 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt137) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt137 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt139) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt139 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt140) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt140 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt142) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt142 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt143) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt143 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt145) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt145 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt146) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt146 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt148) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt148 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt149) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt149 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt151) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt151 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt152) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt152 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt154) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt154 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt155) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt155 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt157) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt157 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt158) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt158 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt160) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt160 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt161) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt161 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt163) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt163 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt164) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt164 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt166) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt166 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt167) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt167 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt169) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt169 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt170) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt170 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt172) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt172 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt173) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt173 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt175) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt175 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt176) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt176 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt178) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt178 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt179) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt179 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt181) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt181 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt182) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt182 + PACKET_OVERHEAD, len);
    p += len;

    len = sizeof(pkt184) - PACKET_OVERHEAD;
    memcpy(p, (unsigned char *)pkt184 + PACKET_OVERHEAD, len);
    p += len;

    p -= packetSize;

    len = enctype1_wrapper(secureKey, (unsigned char *)p, packetSize);

    for (i = 0; i < len / 6; i++)
    {
        printf("%u.%u.%u.%u:%hu\n",
            p[0], p[1], p[2], p[3],
            (unsigned short)((p[4] << 8) | p[5]));

        p += 6;
    }

    printf("Servers: %d\n", i);

    exit(0);
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
