Nilorea Library
C utilities for networking, threading, graphics
n_crypto.c File Reference

vigenere encode decode function More...

#include "nilorea/n_common.h"
#include "nilorea/n_base64.h"
#include "nilorea/n_crypto.h"
#include "nilorea/n_thread_pool.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/sysinfo.h>
+ Include dependency graph for n_crypto.c:

Go to the source code of this file.

Data Structures

struct  CYPHER_PARAM
 structure of a n_vigenere_cypher_thread param More...
 

Functions

N_STRn_get_cpu_id ()
 get the CPU id More...
 
N_STRn_get_current_dir_hd_serial ()
 get the serial of the current running dir hosting disk More...
 
N_STRn_vigenere_cypher (N_STR *input, N_STR *key, bool encipher, bool in_place)
 encode or decode input using vigenere cypher More...
 
void * n_vigenere_cypher_thread (void *ptr)
 encode or decode threaded func using params from ptr More...
 
N_STRn_vigenere_decode (N_STR *string, N_STR *key)
 decode input using vigenere cypher and key More...
 
int n_vigenere_decode_file (N_STR *in, N_STR *out, N_STR *key)
 directly vigenere decode a file using key More...
 
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 More...
 
N_STRn_vigenere_decode_in_place (N_STR *string, N_STR *key)
 decode input using vigenere cypher and key More...
 
N_STRn_vigenere_decode_qa (N_STR *input_data, N_STR *question, N_STR *answer)
 directly vigenere decode a file using key More...
 
N_STRn_vigenere_encode (N_STR *string, N_STR *key)
 encode input using vigenere cypher and key More...
 
int n_vigenere_encode_file (N_STR *in, N_STR *out, N_STR *key)
 directly vigenere encode a file using key More...
 
int n_vigenere_encode_file_qa (N_STR *in, N_STR *out, N_STR *question, N_STR *answer)
 directly vigenere encode a file using question and answer More...
 
N_STRn_vigenere_encode_in_place (N_STR *string, N_STR *key)
 encode string in place using vigenere cypher and key More...
 
N_STRn_vigenere_encode_qa (N_STR *input_data, N_STR *question, N_STR *answer)
 directly vigenere encode a file using key More...
 
N_STRn_vigenere_get_answer (N_STR *root_key, N_STR *question)
 get an answer from a root key and a question More...
 
N_STRn_vigenere_get_question (size_t question_size)
 get a question generated from the current machine hardware (disk&cpu) More...
 
N_STRn_vigenere_get_rootkey (size_t rootkey_size)
 get a rootkey randomly generated More...
 
N_STRn_vigenere_quick_decode (N_STR *encoded_data)
 quick decode data More...
 
N_STRn_vigenere_quick_encode (N_STR *decoded_data)
 quick encode data More...
 

Variables

static char * __internal_root_key = "ENOFGLUCUNZJADRDMCZZSACRBKXAGSLTTFCICPALKHMWWGLVUIFYSLQJIHHXSHOZGRABFNBHGVTOMEBTVIPXZJHHEKIYWNVTWQKERROCTXFGMMLYUJSJFWLFCHQQMMUM"
 static internal root key, just to obfuscate text so we do not care if is is public More...
 

Detailed Description

vigenere encode decode function

Author
Castagnier Mickael
Version
1.0
Date
10/11/2022

Definition in file n_crypto.c.


Data Structure Documentation

◆ CYPHER_PARAM

struct CYPHER_PARAM

structure of a n_vigenere_cypher_thread param

Definition at line 232 of file n_crypto.c.

+ Collaboration diagram for CYPHER_PARAM:
Data Fields
N_STR * dest destination
bool encipher 1 encoding, 0 decoding
size_t end_pos output starting point
N_STR * input input data
N_STR * key encoding/decoding key
size_t start_pos input starting point

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 9 of file n_crypto.c.

◆ _GNU_SOURCE_WAS_NOT_DEFINED

#define _GNU_SOURCE_WAS_NOT_DEFINED

Definition at line 10 of file n_crypto.c.

Function Documentation

◆ n_get_cpu_id()

N_STR * n_get_cpu_id ( )

get the CPU id

Returns
a N_STR *cpuid

Definition at line 139 of file n_crypto.c.

References char_to_nstr(), and nstrprintf.

Referenced by n_vigenere_get_question().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_get_current_dir_hd_serial()

N_STR * n_get_current_dir_hd_serial ( )

get the serial of the current running dir hosting disk

Returns
a N_STR *serial which contain actual running path disk id

Definition at line 72 of file n_crypto.c.

References _nstr, _str, Free, free_nstr, LOG_ERR, n_log, n_popen(), and nstrprintf.

Referenced by n_vigenere_get_question().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_vigenere_cypher()

N_STR * n_vigenere_cypher ( N_STR input,
N_STR key,
bool  encipher,
bool  in_place 
)

encode or decode input using vigenere cypher

Parameters
inputsource to encode/decode
keykey to use for the encoding/decoding
encipherbool, set to 1 => encode, 0 => decode
in_placebool, set to 1 => use input as output string , 0 return a new encoded copy
Returns
a N_STR *encoded or *decoded string

Definition at line 317 of file n_crypto.c.

References __n_assert, _nstr, add_threaded_process(), destroy_threaded_pool(), DIRECT_PROC, LOG_ERR, Malloc, n_log, n_vigenere_cypher_thread(), new_thread_pool(), nstrdup(), refresh_thread_pool(), and wait_for_threaded_pool().

Referenced by n_vigenere_decode(), n_vigenere_decode_in_place(), n_vigenere_encode(), and n_vigenere_encode_in_place().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_vigenere_cypher_thread()

void * n_vigenere_cypher_thread ( void *  ptr)

encode or decode threaded func using params from ptr

Parameters
ptra CYPHER_PARAM *param struc
Returns
NULL

Definition at line 254 of file n_crypto.c.

References __n_assert, Free, n_islower(), n_isupper(), n_mathmod, n_tolower(), and n_toupper().

Referenced by n_vigenere_cypher().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_vigenere_decode_in_place()

N_STR * n_vigenere_decode_in_place ( N_STR string,
N_STR key 
)

decode input using vigenere cypher and key

Parameters
stringsource to decode
keykey to use for the encoding/decoding
Returns
a N_STR *decoded

Definition at line 489 of file n_crypto.c.

References n_vigenere_cypher().

Referenced by n_vigenere_decode_file(), n_vigenere_decode_qa(), and n_vigenere_encode_qa().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_vigenere_encode_in_place()

N_STR * n_vigenere_encode_in_place ( N_STR string,
N_STR key 
)

encode string in place using vigenere cypher and key

Parameters
stringsource to encode
keykey to use for the encoding/decoding
Returns
A pointer to string or an error

Definition at line 476 of file n_crypto.c.

References n_vigenere_cypher().

Referenced by n_vigenere_encode_file(), n_vigenere_encode_qa(), and n_vigenere_quick_encode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ __internal_root_key

char* __internal_root_key = "ENOFGLUCUNZJADRDMCZZSACRBKXAGSLTTFCICPALKHMWWGLVUIFYSLQJIHHXSHOZGRABFNBHGVTOMEBTVIPXZJHHEKIYWNVTWQKERROCTXFGMMLYUJSJFWLFCHQQMMUM"
static

static internal root key, just to obfuscate text so we do not care if is is public

Definition at line 42 of file n_crypto.c.

Referenced by n_vigenere_quick_decode(), and n_vigenere_quick_encode().