Fawkes API Fawkes Development Version
qa_worldinfo_encryption.cpp
1
2/***************************************************************************
3 * qa_worldinfo_encrypt.cpp - Fawkes QA WorldInfo encryption
4 *
5 * Created: Fri May 04 13:38:50 2007
6 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24/// @cond QA
25
26#include <netcomm/worldinfo/decrypt.h>
27#include <netcomm/worldinfo/encrypt.h>
28
29#include <cstddef>
30#include <cstdlib>
31#include <cstring>
32#include <iostream>
33
34using namespace std;
35using namespace fawkes;
36
37#define MAXLENGTH 1200
38
39int
40main(int argc, char **argv)
41{
42 // ArgumentParser *argp = new ArgumentParser(argc, argv, "rl");
43
44 WorldInfoMessageEncryptor *e = new WorldInfoMessageEncryptor((const unsigned char *)"QAKEY",
45 (const unsigned char *)"QAIV123456");
46 WorldInfoMessageDecryptor *d = new WorldInfoMessageDecryptor((const unsigned char *)"QAKEY",
47 (const unsigned char *)"QAIV123456");
48
49 char *input = (char *)malloc(MAXLENGTH);
50 char *output = (char *)malloc(MAXLENGTH);
51 e->set_plain_buffer(input, MAXLENGTH);
52 char *crypted = (char *)malloc(e->recommended_crypt_buffer_size());
53 e->set_crypt_buffer(crypted, e->recommended_crypt_buffer_size());
54
55 strncpy(input, "Test String 12345", MAXLENGTH);
56 printf("Plain text: %s\n", input);
57
58 e->set_plain_buffer(input, strlen(input));
59 long unsigned int bytes = e->encrypt();
60
61 printf("Encrypted to %lu bytes ", bytes);
62 //for (size_t i = 0; i < bytes; i += 4) {
63 // printf("%x", crypted[i]);
64 //}
65 printf("\n");
66
67 memset(output, 0, MAXLENGTH);
68 d->set_crypt_buffer(crypted, bytes);
69 d->set_plain_buffer(output, MAXLENGTH);
70 bytes = d->decrypt();
71
72 printf("Decrypted to %lu bytes: %s\n", bytes, output);
73
74 free(input);
75 free(output);
76
77 delete e;
78 delete d;
79 //delete argp;
80 return 0;
81}
82
83/// @endcond
Fawkes library namespace.