POK
/home/jaouen/pok_official/pok/trunk/libpok/protocols/ceasar/ceasar.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Mon Dec  7 15:16:48 2009 
00015  */
00016 
00024 #include <protocols/ceasar.h>
00025 #include <libc/string.h>
00026 #include <types.h>
00027 
00028 #ifdef POK_NEEDS_PROTOCOLS_CEASAR
00029 
00034 void pok_protocols_ceasar_marshall (void* uncrypted_data, pok_size_t uncrypted_size, void* crypted_data, size_t* crypted_size)
00035 {
00036    uint8_t* uncrypted;
00037    uint8_t* crypted;
00038    size_t   tmp;
00039 
00040    uncrypted   = (uint8_t*) uncrypted_data;
00041    crypted     = (uint8_t*) crypted_data;
00042 
00043    for (tmp = 0 ; tmp < uncrypted_size ; tmp++)
00044    {
00045          crypted[tmp] = (uncrypted[tmp] + 4) % 255;
00046    }
00047 
00048    *crypted_size = uncrypted_size;
00049 }
00050 
00051 
00056 void pok_protocols_ceasar_unmarshall (void* crypted_data, pok_size_t crypted_size, void* uncrypted_data, size_t* uncrypted_size)
00057 {
00058    uint8_t* uncrypted;
00059    uint8_t* crypted;
00060    size_t   tmp;
00061 
00062    uncrypted   = (uint8_t*) uncrypted_data;
00063    crypted     = (uint8_t*) crypted_data;
00064 
00065    for (tmp = 0 ; tmp < crypted_size ; tmp++)
00066    {
00067          uncrypted[tmp] = (crypted[tmp] - 4) % 255;
00068    }
00069 
00070    *uncrypted_size = crypted_size;
00071 }
00072 
00073 #endif
00074