Code Encoding and Decoding in C Language
Code Encoding and Decoding in C Language
Date 03/09/2024
1
effectively restoring the original content.
Time Logging: The program records the exact
time of execution in a separate file (Llave.txt),
which can be used as a reference or part of the
Code Encoding and
encryption key.
File Processing: The original file is read and
1
Advanced programming
Date 03/09/2024
Decryption: The process of converting ciphertext back to processed before generating a new key.
plaintext using the correct key and the corresponding #define RASCII 256: Defines the range of ASCII values for
algorithm. encryption, which includes all possible values of a char in C.
Technical Details:
Namespace: In C, data is processed through functions that
operate on arrays of bytes or characters. For example,
encoding a string involves transforming each byte according [3]
to a particular encoding scheme. int generarClave(int semilla, int posicion): This function
Algorithms: The algorithms used for encoding and decoding generates a pseudo-random key for encryption based on a seed
in C can vary in complexity, ranging from simple operations and a position.
(like XOR for basic encryption) to advanced cryptographic srand(semilla + posicion): Sets the seed for the rand function,
algorithms (such as AES or RSA). adding the seed (usually based on time) and the position.
Key Management: In encryption, a key is required to encode, return rand() % RASCII: Returns a value between 0 and 255
and the same or a related key is needed to decode. The (i.e., within the range of RASCII), which will serve as the
security of the process depends on the robustness of the encryption key.
algorithm and the protection of the key.
V. METHODOLOGY
[5]
1. Alberto it was alone so he does it everything
char decodificarCaracter(char c, int clave): This function takes
2. Alberto does the idea for the encoding
an encrypted character and a key, and returns the original
3. Alberto does the encoding in the Codeblocks app
character.
4. Alberto corrected the errors.
(c - clave + RASCII) % RASCII: Subtracts the key from the
5. Alberto checks that the code run very well
ASCII value of the encrypted character and ensures the result
6. Alberto Does the report
is within the ASCII range by adding RASCII before applying
In this part I’m going to put all my code with the
the modulus.
information line per line.
[6]
[1] void Hora(const char *Llave): This function records the exact
#include <stdio.h>: Includes the standard input/output library execution time of the program in a file named Llave.
in C, necessary for using functions like printf, fopen, fgets, time_t ahora = time(NULL): Gets the current time in seconds
fputs, etc. since the "Epoch" (January 1, 1970).
#include <stdlib.h>: Includes the standard library, which is struct tm *tiempoLocal = localtime(&ahora): Converts the
necessary for functions like rand, srand, and malloc. obtained time into a tm structure containing the components of
#include <time.h>: Includes the library that handles time- the local time (hours, minutes, seconds).
related functions, such as time and localtime. r = fopen(Llave, "w"): Opens the Llave file in write mode.
fprintf(r, "Hora de ejecución: %02d:%02d:%02d\n", ...):
Writes the execution time in the file in "HH:MM" format.
fclose(r): Closes the Llave file.
[2]
#define Almacenamiento 256: Defines a buffer size for storing
data read from the file.
#define Rotacion 5: Defines how many characters should be
2
Advanced programming
Date 03/09/2024
[10]
Ilustración 1. This is the original text that I put in the nots, so in the
next photo we will see this text encoding
[8]
void decodificarArchivo(const char *Encriptado, const char
*Desencriptado, int semilla): This function decrypts the
content of an Encriptado file and saves it in a Desencriptado
file.
The structure is very similar to cifrarArchivo, but the
decodificarCaracter function is used to reverse the encoding.
[11]
Ilustración 2. in this photo we see the initial text encoding, in my
code i use all ASCII code, so we see all the characters
[9]
int semilla = time(NULL);: Gets the current time in seconds
3
Advanced programming
Date 03/09/2024
B. Individual conclusion
The importance of encrypted codes lies in their ability to
protect sensitive information from unauthorized access
and potential breaches. In today’s digital world, where
data is constantly at risk of being compromised,
encryption serves as a vital tool in safeguarding
information. The process of decryption, which reverses
the encryption using a specific key, is equally important
as it allows authorized users to regain access to the
original data. Without the correct key, the encrypted data
remains secure, emphasizing the necessity of proper key
management and the use of reliable encryption methods to
ensure the integrity and confidentiality of the information.
C. Individual contribution (what did you do for this
work?)
Alberto it was alone so he does everything in this
case
REFERENCES
[1] Kochan, S. G. (2014). Programming in C (4th ed.). Addison-Wesley
Professional.
[2] Oualline, S. (1997). Practical C Programming (3rd ed.). O'Reilly Media.
[3] King, K. N. (2008). C Programming: A Modern Approach (2nd ed.). W.
W. Norton & Company.
[4] Prata, S. (2013). C Primer Plus (6th ed.). Addison-Wesley Professional.