Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Code Encoding and Decoding in C Language

This document details the development of an encoder and decoder in C programming, focusing on data encryption and decryption processes. It outlines the methodology, technical details, and applications for secure communication, file storage, and access control systems. The report concludes with discussions on the effectiveness of the code and the importance of encryption in protecting sensitive information.

Uploaded by

aldamanapuerto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Code Encoding and Decoding in C Language

This document details the development of an encoder and decoder in C programming, focusing on data encryption and decryption processes. It outlines the methodology, technical details, and applications for secure communication, file storage, and access control systems. The report concludes with discussions on the effectiveness of the code and the importance of encryption in protecting sensitive information.

Uploaded by

aldamanapuerto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Advanced programming

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

Decoding in C processed in chunks, with each character being


encrypted or decrypted before being written to the
output file.
Language 2.

Some of the real application for this problem are:
Data Encryption in Communication: This type
Alberto Puerto Rodriguez 326495 of solution can be applied in secure
communication systems where messages need to
In this report, I will explain what an encoder and decoder are be encrypted before transmission and decrypted
in the C programming language. Additionally, I will provide a upon receipt. For example, in email services or
step-by-step explanation of how I created my own encoder. messaging apps, where ensuring that the content
remains confidential during transit is crucial.
Code, Decoding, Encoding, Language C  Secure File Storage: In industries like finance or
healthcare, sensitive data needs to be stored
I. INTRODUCTION securely. A similar encryption and decryption
Encoding is the process of converting data from one format to approach could be used to protect files containing
another, usually to facilitate transmission, storage, or to personal or financial information.
protect the information. In the context of C programming,  Access Control Systems: The solution could be
encoding can involve various types of transformations. used in access control systems where logs need to
be securely recorded, ensuring that information
such as access times is encrypted to prevent
II. PROBLEM DESCRIPTION
tampering.
1. Specific needs:
 Data Security: The need to secure the contents of III. THEORETICAL BACKGROUND
a file by converting it into an encrypted format to
prevent unauthorized access. Encoding is the process of converting data from one format to
another, usually to facilitate transmission, storage, or to
 Decryption: The ability to accurately revert the
protect information. In the context of C programming,
encrypted data back to its original form.
encoding can involve various types of transformations:
 Time Logging: The requirement to log the exact Character Encoding: Converting text or data into an encoded
time when the encoding and decoding process is format, such as ASCII, UTF-8, or escape encoding to
executed. represent special characters.
 Efficiency: The program should handle files Data Encoding: Transforming data into a different
efficiently, processing the contents in a manner representation, such as base64 encoding, which converts
that maintains the integrity of the data while binary data into a readable text representation.
performing encryption and decryption. Encryption: A form of encoding intended to protect data by
 Key Generation: A key is generated using a converting plaintext into ciphertext using an algorithm and a
combination of a seed value (current time) and the key. This ciphertext is not understandable without the correct
character's position in the file. This ensures that the key.
encryption key is unique and unpredictable. Decoding is the reverse process of encoding, where the
 Character Encryption: Each character from the encoded data is transformed back to its original form.
original file is encrypted using a rotation-based Technically, decoding in C involves:
cipher, with the generated key being applied to Character Decoding: Converting data from an encoded
shift the ASCII value of each character. representation (such as UTF-8 or an escape sequence) back to
 Character Decryption: The encrypted characters its original format.
are then decoded by reversing the rotation process, Data Decoding: Reversing the transformation applied in data
encoding, such as converting a base64 string back to its
original binary form.
1

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.

IV. MATERIALS [4]


Laptop: Is a portable computer that combines all the char cifrarCaracter(char c, int clave): This function takes a
functions of a desktop computer into a compact and portable character and a key, and returns the encrypted character.
form. Laptops are designed to be lightweight and easy to (c + clave) % RASCII: Adds the key to the ASCII value of the
carry, allowing users to perform computing tasks in various character and then applies the RASCII modulus to ensure the
locations without being tied to a desk. result is within the range of ASCII values.

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

and uses it as a seed to generate the encryption keys.


char Original[] = "LecturaOriginal.txt";: Defines the name of
the original file.
char Encriptado[] = "LecturaEncriptada.txt";: Defines the
name of the encrypted file.
char Desencriptado[] = "LecturaDesencriptada.txt";: Defines
the name of the decrypted file.
char Llave[] = "Llave.txt";: Defines the name of the file that
[7] will store the execution time.
void cifrarArchivo(const char *Original, const char Hora(Llave);: Calls the Hora function to save the execution
*Encriptado, int semilla): This function encrypts the content of time in Llave.txt.
an Original file and saves it in an Encriptado file. cifrarArchivo(Original, Encriptado, semilla);: Calls the
FILE *p, *q: Declares file pointers to handle input (p) and function to encrypt the original file.
output (q) files. decodificarArchivo(Encriptado, Desencriptado, semilla);:
char buffer[Almacenamiento]: Declares a buffer to Calls the function to decrypt the encrypted file.
temporarily store the content read from the file. return 0;: Ends the program successfully.
p = fopen(Original, "r"): Opens the original file in read mode. SCHUDEL
q = fopen(Encriptado, "w"): Opens the encrypted file in write To 7 pm to 7:30 pm Alberto thinks an idea to make an
mode. encoding.
while (fgets(buffer, Almacenamiento, p) != NULL): Reads To 8 pm to 11 pm Alberto starts to make the code, but it
lines from the original file into the buffer. was a prototype.
for (i = 0; buffer[i] != '\0'; i++): Iterates through each character The next day to 5 pm to 8 pm continue making the code but
in the buffer. it was de final code.
if (i % Rotacion == 0): If the index i is divisible by Rotacion, To 8 pm to 11 pm the code was finally over and start to
generates a new key. make some test in the code/.
buffer[i] = cifrarCaracter(buffer[i], clave): Encrypts the
character using the key. VI. EXPERIMENTATION AND RESULTS
fputs(buffer, q): Writes the encrypted buffer to the Encriptado
file.
fclose(p): Closes the original file.
fclose(q): Closes the encrypted file.

[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

experts, reducing the likelihood of vulnerabilities.


Flexibility: Libraries like OpenSSL offer a wide range of
cryptographic functions beyond just encryption and
decryption, including digital signatures, hashing, and
secure communications.
3. Multithreading for Improved Performance
[12] Implement multithreading to parallelize the encryption
Ilustración 3. The decoding part it works so we see the original text and decryption processes. For example, divide the file
in this part.
into chunks and encrypt/decrypt each chunk in a separate
thread.
 Advantages:
Performance: Multithreading can significantly speed up
the processing of large files, especially on multi-core
processors. By dividing the workload across multiple
threads, the time required for encryption and decryption
can be reduced.
[13] Scalability: The approach can scale with the number of
Ilustración 4. This the moment that the program runs, this is
available cores on the CPU, providing better performance
necessary if someone needs to decoding the program to have the
original text. on more powerful hardware.
Responsiveness: Multithreading can improve the
responsiveness of the program by allowing other
● Alternative solutions
operations to continue while encryption or decryption is
1. Hardware-Based Encryption being performed.
Replace the software-based encryption algorithm with
hardware-based encryption using a Trusted Platform VII. DISCUSSION OF RESULTS
Module (TPM) or Hardware Security Module (HSM).
1. This section discusses the obtained results.
The encryption and decryption operations will be
2. Answer the following question:
offloaded to the dedicated hardware, which is designed
a. Why are they obtained results correct?
for secure cryptographic operations.
Yes, the results are excellent, because my
 Advantages:
code runs very well, the encryption makes a
Security: Hardware-based encryption is significantly
great job and do all I wanted, even de
more secure than software-based encryption. It is resistant
desencryption works so well that put me the
to many types of attacks, such as memory scraping or
exact code in another text, even the key its
cold boot attacks.
very useful.
Performance: Offloading cryptographic operations to
dedicated hardware can significantly improve the
VIII. CONCLUSIONS
performance of the encryption and decryption processes.
Key Management: TPMs or HSMs provide secure key A. General conclusion
management, ensuring that encryption keys are never The provided C code effectively demonstrates a simple yet
exposed in system memory. functional approach to encrypting and decrypting text files. By
2. Use of a Modern Encryption Library utilizing basic C libraries such as stdio.h, stdlib.h, and time.h,
Replace the custom encryption algorithm with a more the program generates a pseudo-random key based on the
robust and widely-used encryption method from a modern current time and a position index. This key is then used to
encryption library like OpenSSL. modify the ASCII values of characters in the file, ensuring that
Use algorithms such as AES (Advanced Encryption the original content is transformed into an encrypted form.
Standard) for encryption and decryption. The encryption method, while basic, serves as an introduction
 Advantages: to more complex cryptographic processes. However, the
Security: Using a well-established encryption standard simplicity of this method also highlights potential limitations,
like AES is far more secure than custom, ad-hoc particularly in terms of security. A more robust encryption
encryption methods. AES is considered secure by modern technique or hardware-based encryption would significantly
cryptographic standards. enhance the security of the data, making it resistant to modern
Ease of Use: Encryption libraries like OpenSSL are threats.
optimized, well-documented, and maintained by security
4
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.

You might also like