-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_Encrypt.h
211 lines (192 loc) · 7.3 KB
/
_Encrypt.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#ifndef ENCRYPT
#define ENCRYPT
#include <iostream>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <cstdlib>
#include <stdio.h>
#include <vector>
#include <string>
#include <time.h>
#include <sstream>
#include <math.h>
#include <Windows.h>
#include <direct.h>
//#include "Misc.h"
#include "C:\Users\Sam\Documents\GitHub\9-grade-ECET\_Misc.h"
#pragma comment(lib, "winmm.lib")
#define SIZE 3
using namespace std;
vector<int> sizecheck(vector<int> test)
{ //FUNCTION (SIZE CHECK) START
if (test.size() % 3 != 0)
test.push_back(0);
if (test.size() % 3 != 0)
test.push_back(0);
return test;
} //FUNCTION (SIZE CHECK) END
vector<int> Message() //Function Definition
{ //FUNCTION (GET MESSAGE) START
vector<int> a; //New vector, not the same as the one in Ecrypt(), as it is in a different Scope
std::string message = ""; //Makes Local String called message
cout << "Please Enter the Message to Be Encrypted. \n";
while (true) //Infinite Loop, leave it with break
{
getline(cin, message); //Asks for the message they want to encrypt
if (!message.empty())
{
system("CLS"); //Clears Screen
break;
}
else //If theres no message, repeats from the top of the loop
{
continue;
}
}
char choose; //Local Char Choose
int result1 = MessageBox(HWND_DESKTOP, L"Would you Like to See a List of the Text Files in the Current Directory?", L"Text Files?", MB_YESNO);
switch (result1)
{
case IDYES:
{
displaytxtfiles();
int result2 = MessageBox(HWND_DESKTOP, L"Would you like to delete all these files?", L"DELETE", MB_YESNO);
switch (result2)
{
case IDYES:
{
int result = MessageBox(HWND_DESKTOP, L"Are You SURE??", L"Confirmation", MB_YESNO | MB_ICONWARNING);
switch (result)
{
case IDYES:
string c = "del /Q ";
string p = "*.txt";
system(c.append(p).c_str());
break;
}
}
}
break;
}
case IDNO:
{
int result = MessageBox(HWND_DESKTOP, L"Would You like to Clear the Current Folder of ALL Text Files?", L"DELETE", MB_YESNO);
switch (result)
{
int result = MessageBox(HWND_DESKTOP, L"Are You SURE??", L"Confirmation", MB_YESNO | MB_ICONWARNING);
switch (result)
{
case IDYES:
string c = "del /Q ";
string p = "*.txt";
system(c.append(p).c_str());
break;
}
}
}
}
system("pause");
while (true) //Infinite Loop, Leave with breaks
{
system("COLOR 30");
system("CLS"); //Clears Screen
cout << "Please Enter the Desired Filename(Please Exclude the .txt at the end)\n[MAX LENGTH = 128]:\n----> ";
getline(cin, filename); //Getline allows for spaces, instead of traditional cin >>
if (filename.length() == 0)
getline(cin, filename);
if (!checkvalid(filename)) //calls checkvalid on the filename
{
for (int x = 0; x<5; x++)
{
Sleep(250);
cout << lightblue << "\rTHAT IS NOT VALID";
Sleep(250);
cout << lightred << "\rTHAT IS NOT VALID";
}
Sleep(1000);
system("CLS");
continue;
}
string directory;
filename += ".txt"; //Adds .txt to end of string, since user was specified NOT to add .txt at end
int result = MessageBox(HWND_DESKTOP, L"Would you like to pick a certain directory?", L"Confirmation", MB_YESNO | MB_ICONWARNING);
switch (result)
{
case IDYES:
{
cout << "Enter the Specified Directory (Ex. C:\\Users\\Me\\)<---Please dont forget last \\\n----> ";
getline(cin, directory);
filename = directory + filename;
break;
}
case IDNO:
{
break;
}
}
//If they did, it will look like filename.txt.txt
if (!filename.empty()) //If the filename is not empty
{
system("CLS"); //Clears Screen
cout << "Your File is: \n" << filename << endl; //Shows User their inputted Filename
cout << "And your Message is: \n" << message << endl; //Along with the Message
system("PAUSE"); //Pauses the Screen
break; //Leaves the Loop
}
else //If the Message is empty
{
continue; //Stay in the Loop
}
}
for (int count = 0; count < message.length(); count++)
{
char y = message.at(count); //takes each character of the message
a.push_back(static_cast<int>(y)); //Pushes it into a vector of Ints(using static cast)
}
a = sizecheck(a); //Calls SizeCheck , and checks size of vector<int> a
return a; //Function Returns a
} //FUNCTION (GET MESSAGE) END
//*****************************************************************************************************************************************************************************
//*****************************************************************************************************************************************************************************
void randKey(float key[SIZE][SIZE]) //Function Definition
{ //FUNCTION (GENERATE RANDOM KEY) START
srand(time(0)); //"Changing" Seed, as Time is never constant
for (int i = 0; i < SIZE; i++)
for (int j = 0; j < SIZE; j++)
key[i][j] = rand() % 9 + 1; //Key is assigned a random value, for every "square"
} //FUNCTION (GENERATE RANDOM KEY) END
//*****************************************************************************************************************************************************************************
//*****************************************************************************************************************************************************************************
void outputkey(ofstream& Stuff) //Function Definition
{ //FUNCTION (WRITE KEY TO FILE) START
for (int i = 0; i < SIZE; i++)
for (int j = 0; j < SIZE; j++)
Stuff << key[i][j]; //Outputs the Matrix into the Text File
} //FUNCTION (WRITE KEY TO FILE) END
//*****************************************************************************************************************************************************************************
//*****************************************************************************************************************************************************************************
ofstream createtxt()
{ //FUNCTION (MAKE TXT FILE) START
//****************************************************
ofstream Stuff; //**** Makes The Text File
Stuff.open(filename.c_str()); //****
//****************************************************
return Stuff; //Returns Location of Stuff
} //FUNCTION (MAKE TXT FILE) END
void Encrypt() //Function Definition
{ //FUNCTION (MAIN ENCRYPT) START
randKey(key); //Calls the RandKey Function
vector<int> a = Message(); //Calls Message, returning value is stored in a
remove(filename.c_str()); //Deletes the File if It Already Exists
ofstream Stuff = createtxt(); //Calls createtxt, stored into the ofstream object
outputkey(Stuff); //Calls Outputkey, with the parameter of the Address of Stuff
a = MatrixMultiply(key, a); //A is overwritten, and is multiplied by the key before doing so
Stuff << endl
<< a //Vector is written into the textfile, no need to iterate due to the template
<< endl;
Stuff.close(); //Closes the File
} //FUNCTION (MAIN ENCRYPT) END
//*****************************************************************************************************************************************************************************
//*****************************************************************************************************************************************************************************
#endif