When the A2 program is run, apart from the name of the program, the program should take two command line arguments: 1. The name of the file to be encrypted/decrypted using the XOR operation and 2. The password for encrypting/decrypting the file.
For example, if the name of the file to be encrypted/decrypted is "auckland.jpg" and the password is "abcd1234", the command below is used to run the program ("$" is the command window prompt):
$ ./A2 auckland.jpg abcd1234
The result of the encryption/decryption should be stored in a file. The name of the file is the name of the original file with a "new-" prefix. For example, if the name of the original file is "auckland.jpg", the name of the file containing the result of the encryption/decryption operation should be "new-auckland.jpg". You can assume that the name of the file to be encrypted/decrypted consists of at most 15 characters.
In this part of the program you will need to make sure that the program is passed two command line arguments. If not, the following message should be displayed:
Usage: ./A2 filename password
This must be handled in the main() function of the program.
Part 2 (15 marks)
In this part of the program you will need to define two functions: 1. The make_new_name() function that takes two pointers to character arrays as its parameters. The first parameter new_name, points to the character array that will be used to store the new filename. In other words, the name of the file that will store the result of the encryption/decryption operation. The second parameter original_name, points to the character array that contains the characters of the original filename. This function should populate the character array pointed to by new_name so that it contains the characters "new-" followed by the original file name as discussed above. 2. The length_of_password() function that takes one parameter, password, which is a pointer to the character array that stores the password characters. This function should return an integer value indicating the length of the password.
You can call these functions in the main() function and then print the values of both the name of the new file and the length of the password in the format shown below. The output of the program is highlighted in red. Please note that "auckland.jpg" is the exact name of the file. That is, the file name does NOT have a ".txt" and any other suffix.
Note: Markers will probably use a file with a different name and a different password.
Part 2 (30 marks)
In this part of the assignment, you will need to define the following 3 functions: 1. The is_alpha() function that takes a single parameter c of type char. The function returns 1 if c is an alphabetical character and 0 otherwise. Both lowercase and uppercase alphabetical characters should be considered. 2. The is_digit() function that takes a single parameter c of type char. The function returns 1 if c is a numerical character between 0 and 9 inclusive, and 0 otherwise. 3. The is_valid_password() function that takes one parameter, password, which is a pointer to the character array that stores the password characters. This function will determine whether a password is valid. If a password is valid, the function will return the value 1. If the password is invalid the function will print out one or more messages indicating what is wrong with the password and then return the value 0. The is_valid_password() function will need to use both the is_alpha() and is_digit() functions to determine a password’s validity.