File Management Program

See the full project on GitHub

2023

File Management program implemented in C, designed to allow you to encrypt, decrypt and compress BMP images and TXT files. Utilises the Vigenere Cipher to encrypt and decrypt TXT files.

Background and Context

In this UTS Project, I was tasked with developing a professional-grade program that manipulates real-world data. This project is the culmination of knowledge gained in the Fundamentals of C Programming course. Memory management, separating concerns, data structures and algorithm implementation were key components of this assignment. The project required some form of compression or encryption. I worked in a group, using communication and effective planning to ensure we met the expectations set out in the marking criteria. A Makefile was included to achieve modularity and efficiently manage different program components. It compiles individual source files (.c) into object files (.o) and links them together to generate the final executable (main.out). This approach ensures that the program's different functionalities, such as file I/O, text encryption, and image processing, are separated into distinct modules, allowing for easier maintenance and debugging.

Theoretical Framework

Vigenere encrypting and decrypting/byte addition/subtraction

The encryption/decryption method that we have decided on for text files is a Vigenère Cipher. This is an old method that has been in use since at least the sixteenth century and, while not perfect, still provides a fair level of security today (Simmons, 2023). We chose it for its balance of simplicity and acceptable security that it provides. It is a polyalphabetic form of substitution cipher that uses multiple Caesar ciphers to encrypt a string of text. To decrypt it, the other person would need a key provided by the encryptor. Because the most frequently used letters in the encrypted text do not align with the most frequently used letters in the original text, this makes it particularly hard to crack (Sarkar, 2020). In the program, the Vigenère cipher can be applied to both upper-case and lower-case letters. Any special characters or numbers are encrypted by adding 100 bytes to each character.

XOR encrypting and decrypting

The encryption/decryption method chosen for image files is XOR. This method applies a bitwise XOR operation to encrypt the binary data in an image file. The XOR operation returns true only if one (but not both) of its two arguments is true, and false if neither is true (Weisstein, 2023). To decrypt, the user simply reapplies XOR with the same key, which restores the original image. Although this method is straightforward, it can be vulnerable with image files because it may be relatively easy for an attacker to predict neighbouring pixel values in an encrypted image; however, the distortion introduced still provides a degree of security (Nag et al., 2011).

Error Detection

The program has features designed for multiple errors. Entering a non-existent file name in text encryption or decryption will result in error messages being displayed and the program exiting. There are also messages to compare the result before encryption/decryption of text to after encryption/decryption to ensure it works as desired. Return statements are employed along with messages to the terminal if the user doesn’t input uppercase characters, which is essential for our encryption methods. There are also file handling errors throughout, such as incorrectly applying image encryption to the wrong file type or inputting a non-existent file, which will trigger a return and print a warning message. Additionally, for text functions, if file contents are null or files are unable to be accessed/opened, the same will occur.

User Interface

The use of a simple user interface in plain English means that the program is accessible to any person, no matter their proficiency level with a computer. Text prompts guide the user simply through the necessary steps and list the options available. For example, if the incorrect number of command line arguments is typed, it will return to main and print information to the terminal to indicate how to use the program. Additionally if they type an invalid operation, it will display an error message and return. There are also the functions that return to main. If the key is typed in incorrectly, it will return and print a message to indicate how the key should be inputted.

Huffman Compression

Huffman coding is a lossless data compression algorithm that is based on the frequency of occurrence of a data item (symbol). The principle is to use a lower number of bits to encode the data that occurs more frequently, and a higher number of bits for data that occurs less frequently. A tree-based structure (Huffman Tree) is built where each leaf node represents a symbol, and the path from the root to the leaf represents the symbol's bit-string (code).

Hanly, J. R., & Koffman, E. B. (2015). Problem solving and program design in C (8th ed.). Pearson.

Lake J. (2023. October 27). What is AES Encryption and How Does it Work? Comparitech.com. https://www.comparitech.com/blog/informationsecurity/what-is-aes-encryption/

Nag A, Singh J, Khan S, Ghosh S, Biswas S, Sarkar D, Sarkar P. (2011). Image Encryption Using Affine Transform and XOR Operation. ICSCCN. 309-312.

Sarkar, S. (2020, July 17). How much do you know about the Vigenère cipher? IBM Community. https://community.ibm.com/community/user/ibmz-andlinuxone/blogs/subhasish-sarkar1/2020/07/17/how-much-do-you-knowabout-the-vigenere-cipher

Simmons, G. (2023, April 20). Vigenère cipher. Encyclopedia Britannica. https://www.britannica.com/topic/Vigenere-cipher

Weisstein, E. (2023, November 3). Exclusive Disjunction. Wolfram Web. https://mathworld.wolfram.com/ExclusiveDisjunction.html