qa_worldinfo_encryption.cpp

00001 
00002 /***************************************************************************
00003  *  qa_worldinfo_encrypt.cpp - Fawkes QA WorldInfo encryption
00004  *
00005  *  Created: Fri May 04 13:38:50 2007
00006  *  Copyright  2006-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 /// @cond QA
00025 
00026 #include <netcomm/worldinfo/encrypt.h>
00027 #include <netcomm/worldinfo/decrypt.h>
00028 
00029 #include <cstdlib>
00030 #include <cstddef>
00031 #include <cstring>
00032 #include <iostream>
00033 
00034 using namespace std;
00035 using namespace fawkes;
00036 
00037 #define MAXLENGTH 1200
00038 
00039 int
00040 main(int argc, char **argv)
00041 {
00042   // ArgumentParser *argp = new ArgumentParser(argc, argv, "rl");
00043 
00044   WorldInfoMessageEncryptor *e = new WorldInfoMessageEncryptor((const unsigned char *)"QAKEY",
00045                                                                (const unsigned char *)"QAIV123456");
00046   WorldInfoMessageDecryptor *d = new WorldInfoMessageDecryptor((const unsigned char *)"QAKEY",
00047                                                                (const unsigned char *)"QAIV123456");
00048   
00049 
00050   char *input = (char *)malloc(MAXLENGTH);
00051   char *output = (char *)malloc(MAXLENGTH);
00052   e->set_plain_buffer(input, MAXLENGTH);
00053   char *crypted = (char *)malloc(e->recommended_crypt_buffer_size());
00054   e->set_crypt_buffer(crypted, e->recommended_crypt_buffer_size());
00055 
00056   strncpy(input, "Test String 12345", MAXLENGTH);
00057   printf("Plain text: %s\n", input);
00058 
00059   e->set_plain_buffer(input, strlen(input));
00060   long unsigned int bytes = e->encrypt();
00061 
00062   printf("Encrypted to %lu bytes ", bytes);
00063   //for (size_t i = 0; i < bytes; i += 4) {
00064   //  printf("%x", crypted[i]);
00065   //}
00066   printf("\n");
00067 
00068   memset(output, 0, MAXLENGTH);
00069   d->set_crypt_buffer(crypted, bytes);
00070   d->set_plain_buffer(output, MAXLENGTH);
00071   bytes = d->decrypt();
00072 
00073   printf("Decrypted to %lu bytes: %s\n", bytes, output);
00074 
00075   free(input);
00076   free(output);
00077 
00078   delete e;
00079   delete d;
00080   //delete argp;
00081   return 0;
00082 }
00083 
00084 /// @endcond

Generated on Tue Feb 22 13:32:28 2011 for Fawkes API by  doxygen 1.4.7