Skip to content

Commit afaa755

Browse files
committed
hotfix--D-everywhere development complete
1 parent dc97d07 commit afaa755

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Release version: 1.1.1
2+
3+
* **Change:** -D now works for both encryption and decryption. Deletes source
4+
files if operation was successful.
5+
* **Change:** Usage information changed to mention the above point.
6+
17
## Release version: 1.1.0
28

39
* **Feature:** Output to stdout development complete.

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ will not install it anywhere. So no root is required.
3636
## Usage:
3737

3838
```
39-
tea [-e [-D] |-d [-N] ] [-v] -k '16 byte key' -I <input files...>
40-
-e - Encrypt.
41-
-d - Decrypt.
42-
-D - Delete source files after encryption.
43-
-N - Send decryption output to stdout.
44-
-v - Verbose output.
39+
tea [-e |-d [-N] ] [-D] [-v] -k '16 byte key' -I <...>
40+
-e - Encrypt
41+
Encrypts the input files and the output files of each will be placed in the
42+
-d - Decrypt
43+
Decrypts the input files and the output files of each will be placed in the
44+
-N - When decrypting, display output to stdout.
45+
-D - Deletes source files after encryption or decryption.
46+
-v - Verbose
4547
-k - 16 byte key.
46-
-I - Input files for decryption/encryption.
48+
-I - Files that need to be processed.
49+
50+
Notes:
51+
- Cannot use -D (Delete file), -N (stdout output) together.
52+
- Cannot use -e (encryption), -N (stdout output) together.
53+
- When using -N (stdout output), -v (Verbose) is ignored.
4754
```
4855

4956
## Example:

main.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,29 @@
2323
#define USAGE(p) fprintf(stderr, \
2424
"Tiny Encryption Algorithm implementation, with 128 bit key.\n" \
2525
"Performs Encryption/Decruption of multiple flies.\n" \
26-
"usage:\n%s [-e [-D] |-d [-N] ] [-v] -k '16 byte key' -I <...>\n" \
26+
"usage:\n%s [-e |-d [-N] ] [-D] [-v] -k '16 byte key' -I <...>\n" \
2727
"-e - Encrypt\n" \
2828
" Encrypts the input files and the output files of each" \
2929
" will be placed in the same directory with extension .3\n" \
30-
"-D - Will delete parent files after encryption\n" \
3130
"-d - Decrypt\n" \
3231
" Decrypts the input files and the output files of each" \
3332
" will be placed in the same directory excluding extension .3\n" \
3433
"-N - When decrypting, display output to stdout.\n" \
34+
"-D - Deletes source files after encryption or decryption.\n" \
3535
"-v - Verbose\n" \
3636
"-k - 16 byte key.\n" \
3737
"-I - Files that need to be processed.\n" \
38+
"\nNotes:\n"\
39+
" - Cannot use -D (Delete file), -N (stdout output) together.\n" \
40+
" - Cannot use -e (encryption), -N (stdout output) together.\n" \
41+
" - When using -N (stdout output), -v (Verbose) is ignored.\n" \
3842
, p)
3943

4044
#define MAX_FILENAME_LENGTH 255 // Length of file path
4145
#define MAX_INPUT_FILES 50 // number of files
4246
#define ENCRYPTED_FILE_EXTENSION ".3"
4347

44-
#define FLAG_DELETE_AFTER_ENCRYPTION (1 << 0)
48+
#define FLAG_DELETE_SOURCE_FILE (1 << 0)
4549
#define FLAG_VERBOSE (1 << 1)
4650
#define FLAG_OUTPUT_TO_STDOUT (1 << 2)
4751

@@ -90,10 +94,9 @@ int main(int argc,char *argv[])
9094

9195
// -- 1. Perform Encryption and Decryption --
9296

93-
output_filename[0] = '\0';
94-
9597
if (prm.mode == ENCRYPT) {
9698
// Output file name: InputfilePath + ".3"
99+
output_filename[0] = '\0';
97100
strcat(output_filename, prm.files[i]);
98101
strcat(output_filename, ENCRYPTED_FILE_EXTENSION);
99102
}
@@ -110,7 +113,7 @@ int main(int argc,char *argv[])
110113
// Feature: Output to stdout
111114
if (prm.flags & FLAG_OUTPUT_TO_STDOUT) {
112115
strcpy(output_filename,"(stdout)");
113-
enc_dec_mode = TEA_FLAG_OUTPUT_STDOUT;
116+
enc_dec_mode |= TEA_FLAG_OUTPUT_STDOUT;
114117
printf("-------------- %u: %s --------------\n",
115118
i+1, prm.files[i]);
116119
}
@@ -137,10 +140,8 @@ int main(int argc,char *argv[])
137140
// -- 3. Delete the file if -D option is set --
138141

139142
// Feature: Delete file is -D was provided.
140-
// Delete only if Encryption worked
141-
if (prm.mode == ENCRYPT &&
142-
ed_status == true &&
143-
prm.flags & FLAG_DELETE_AFTER_ENCRYPTION) {
143+
if (ed_status == true &&
144+
prm.flags & FLAG_DELETE_SOURCE_FILE) {
144145
// Feature: verbosity
145146
printf("Deletion: %s : %s\n", prm.files[i],
146147
delete (prm.files[i]) ? "Success": "Failed");
@@ -212,7 +213,7 @@ int readargs(char *argv[], struct op *out)
212213
out->flags |= FLAG_VERBOSE;
213214
break;
214215
case 'D':
215-
out->flags |= FLAG_DELETE_AFTER_ENCRYPTION;
216+
out->flags |= FLAG_DELETE_SOURCE_FILE;
216217
break;
217218
default:
218219
fprintf(stderr,"Error: Invaid argument: %s\n",arg);
@@ -229,21 +230,25 @@ int readargs(char *argv[], struct op *out)
229230

230231
bool args_is_valid(struct op *out)
231232
{
232-
if (out->flags & FLAG_DELETE_AFTER_ENCRYPTION && out->mode == DECRYPT){
233-
fprintf(stderr,
234-
"Error: Delete option is only for Encryption mode.\n");
235-
return false;
236-
}
237233

238234
if (out->flags & FLAG_OUTPUT_TO_STDOUT && out->mode == ENCRYPT){
239235
fprintf(stderr,
240236
"Error: -N option can only be used in Decrypt mode.\n");
241237
return false;
242238
}
243239

240+
if (out->flags & FLAG_OUTPUT_TO_STDOUT &&
241+
out->flags & FLAG_DELETE_SOURCE_FILE) {
242+
fprintf(stderr,
243+
"Warning: -D is ignored when outputing to stdout.\n");
244+
245+
// Remove -D flag
246+
out->flags &= ~FLAG_DELETE_SOURCE_FILE;
247+
}
248+
244249
if (out->flags & FLAG_OUTPUT_TO_STDOUT && out->flags & FLAG_VERBOSE) {
245250
fprintf(stderr,
246-
"Warning: -v option has no effect with -N option.\n");
251+
"Warning: -v is ignored when outputing to stdout.\n");
247252

248253
// Clear verbose flag
249254
out->flags &= ~FLAG_VERBOSE;

0 commit comments

Comments
 (0)