-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_vigenere.h
More file actions
56 lines (49 loc) · 2.2 KB
/
common_vigenere.h
File metadata and controls
56 lines (49 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright [2020]<Jonathan David Rosenblatt>
#ifndef COMMON_VIGENERE_H_
#define COMMON_VIGENERE_H_
typedef struct vigenere_cipher {
unsigned char* key;
unsigned int
lastKeyIndex; // Me guardo la última posición de la clave que usé.
} vigenere_cipher_t;
/*
* Inicializa el cipher dada una key válida. También guardará la última posición
* de la key por la que pasó por si tuviera que cortar el proceso de codificado
* a la mitad.
* Precondiciones: cipher != NULL && key != NULL.
* Postcondiciones: deja el cipher recibido inicializado. Se devuelve -1 si
* ocurre un error, 0 de lo contrario.
*/
int vigenere_cipher_init(void* cipher, unsigned char* key);
/*
* Dado un cipher válido, un mensaje y su largo se codifica o descodifica el
* mismo. Se sumarán bytes al codificar y restarán al decodificar en función de
* si estoyCifrando es 1 o -1, respectivamente. Precondiciones: cipher != NULL
* && cipher inicializado && string != NULL && estoyCifrando = 1 o -1
* Postcondiciones: se sobreescribirá el mensaje con su versión cifrada. Se
* devuelve -1 si ocurre un error, 0 de * lo contrario.
*/
int vigenere_cipher_shift_bytes(vigenere_cipher_t* cipher, int estoyCifrando,
unsigned char msg[], unsigned int msgLen);
/*
* Dado un cipher válido y un mensaje se codifica el mismo.
* Precondiciones: cipher != NULL && cipher inicializado && string != NULL
* Postcondiciones: se sobreescribirá el mensaje con su versión cifrada. Se
* devuelve -1 si ocurre un error, 0 de * lo contrario.
*/
int vigenere_encode(void* cipher, unsigned char msg[], unsigned int msgLen);
/*
* Dado un cipher válido, un mensaje y el largo del mismo se decodifica el
* mismo.
* Precondiciones: cipher != NULL&& cipher inicializado && string != NULL
* Postcondiciones: se sobreescribirá el mensaje con su versión descifrada.
* Se devuelve -1 si ocurre un error, 0 de * lo contrario.
*/
int vigenere_decode(void* cipher, unsigned char msg[], unsigned int msgLen);
/*
* Destruye el cipher recibido, liberando todos los recursos que este pueda
* estar usando.
* Postcondiciones: libera todos los recursos asociados.
*/
void vigenere_destroy(void* cipher);
#endif // COMMON_VIGENERE_H_