-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencryptjpeg.cpp
54 lines (46 loc) · 915 Bytes
/
encryptjpeg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Mark Watson
// CS 306
// Semester Project
#include <iostream>
#include <iomanip>
#include "accessjpeg.h"
#include "aesencrypt.h"
#include "encryptjpeg.h"
bool encryptJpeg::process(char action)
{
char * ptr; // ptr to a block
bool in_success;
bool out_success;
// get file, returns errors if can't find
in_success = file.readInFile(in_file);
if (!in_success)
{
throw invalidInFile();
return false;
}
// set the key
encrypter.setTextKey(key);
// do the encryption
while (file.hasMore())
{
ptr = file.accessBlock(); // get a block of the image
if (action == 'e')
{
encrypter.encryptBlock(ptr); // run the encryption
}
else if (action == 'd')
{
encrypter.decryptBlock(ptr);
}
else
{
throw invalidAction();
return false;
}
}
// write out the file
out_success = file.writeOutFile(out_file);
if (!out_success)
throw invalidOutFile();
return true;
}