14int main(
int argc ,
char *argv[] )
19 fprintf( stderr,
"%s usage:\n"
20 " -i input_file [optional] use a file as datas instead of hard coded 3 lines text\n"
22 " -V log level: LOG_INFO, LOG_NOTICE, LOG_ERR, LOG_DEBUG\n"
23 " -h help\n" , argv[ 0 ] );
27 int getoptret = 0, ret = 0 ,
30 N_STR *input_name = NULL ;
37 while( ( getoptret = getopt( argc, argv,
"i:hvV:" ) ) != EOF)
45 fprintf( stderr,
"Date de compilation : %s a %s.\n", __DATE__, __TIME__ );
48 if( !strncmp(
"LOG_NULL", optarg, 5 ) )
54 if( !strncmp(
"LOG_NOTICE", optarg, 6 ) )
60 if( !strncmp(
"LOG_INFO", optarg, 7 ) )
66 if( !strncmp(
"LOG_ERR", optarg, 5 ) )
72 if( !strncmp(
"LOG_DEBUG", optarg, 5 ) )
78 fprintf( stderr,
"%s n'est pas un niveau de log valide.\n", optarg );
91 fprintf( stderr,
" => Missing log level\n" );
93 else if( optopt ==
'p' )
95 fprintf( stderr,
" => Missing port\n" );
97 else if( optopt ==
'i' )
99 fprintf( stderr,
" => Missing filename\n" );
101 else if( optopt !=
's' )
103 fprintf( stderr,
" => Unknow missing option %c\n", optopt );
118 "##############################################################\n"
119 "# This is an example of crypto encode/decode, with a newline #\n"
120 "# This is the end of the test #\n"
121 "##############################################################" );
123 n_log(
LOG_NOTICE,
"Testing crypto, encoding text of size (%ld/%ld):\n%s" , EXAMPLE_TEXT -> written , EXAMPLE_TEXT -> length ,
_nstr( EXAMPLE_TEXT ) );
127 N_STR *key =
char_to_nstr(
"RKCHSLZWFNASULJFVPRVUUUAEUVEMSSGEVNWIMVPZVIWITBGIUBEQVEURBYEWTMCQZZYNWQMRAIBTMHDIKIZHOVZQUFONRQDSRDFNTTGVEKOSTSAEABLOXMGTTWIMPNE" );
170 N_STR *output_name_enc = NULL ;
171 N_STR *output_name_dec = NULL ;
172 N_STR *output_name_dec_question = NULL ;
174 nstrprintf( output_name_enc ,
"%s.crypt_encoded" ,
_nstr( input_name ) );
179 nstrprintf( output_name_dec ,
"%s.crypt_decoded" ,
_nstr( input_name ) );
184 nstrprintf( output_name_dec_question ,
"%s.crypt_decoded_question" ,
_nstr( input_name ) );
187 n_log(
LOG_DEBUG ,
"Decoded with question/answer file saved in %s" ,
_nstr( output_name_dec_question ) );
191 n_log(
LOG_ERR ,
"unable to decode with question answer" );
#define _nstr(__PTR)
N_STR or "NULL" string for logging purposes.
N_STR * n_base64_decode(N_STR *bufcoded)
decode a N_STR *string
N_STR * n_base64_encode(N_STR *input)
encode a N_STR *string
N_STR * n_vigenere_encode_qa(N_STR *input_data, N_STR *question, N_STR *answer)
directly vigenere encode a file using key
int n_vigenere_decode_file_qa(N_STR *in, N_STR *out, N_STR *question, N_STR *answer)
directly vigenere decode a file using question and answer
N_STR * n_vigenere_decode(N_STR *string, N_STR *key)
decode input using vigenere cypher and key
N_STR * n_vigenere_get_answer(N_STR *root_key, N_STR *question)
get an answer from a root key and a question
N_STR * n_vigenere_decode_qa(N_STR *input_data, N_STR *question, N_STR *answer)
directly vigenere decode a file using key
N_STR * n_vigenere_encode(N_STR *string, N_STR *key)
encode input using vigenere cypher and key
int n_vigenere_encode_file(N_STR *in, N_STR *out, N_STR *key)
directly vigenere encode a file using key
int n_vigenere_decode_file(N_STR *in, N_STR *out, N_STR *key)
directly vigenere decode a file using key
N_STR * n_vigenere_get_question(size_t question_size)
get a question generated from the current machine hardware (disk&cpu)
N_STR * n_vigenere_quick_decode(N_STR *encoded_data)
quick decode data
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_NULL
no log output
#define LOG_INFO
informational
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
#define nstrprintf(__nstr_var,...)
Macro to quickly allocate and sprintf to N_STR *.
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
A box including a string and his lenght.
base64 encoding and decoding functions using N_STR
vigenere encoding and decoding functions using N_STR/files
List structures and definitions.
N_STR and string function declaration.