· 5 years ago · Dec 03, 2020, 04:42 AM
1#pragma once
2
3#include "Support-Libary.hpp"
4#include "Cryptography-Algorithm-Util.hpp"
5
6/***声明代码-开始 Declare the code - the beginning***/
7//以下变量,应用到文件被加密时
8//The following variables apply when the file is encrypted
9
10string E_SourceFileName, // 源文件名
11 E_SourceFileMainName, // 源文件主要名
12 E_SourceFileExtendedName, // 源文件扩展名
13 E_TargetFileExtendedName; // 目标文件扩展名
14
15char E_KEY[1024], //File (Encryption or Encrypted) key 文件加密密钥
16 E_KEY2[1024],
17 E_KEY3[1024],
18 E_KEY4[1024];
19/***声明代码-结束 Declare the code - end***/
20
21/***声明代码-开始 Declare the code - the beginning***/
22//以下变量,应用到文件被解密时
23//The following variables apply when the file is decrypted
24
25string D_SourceFileName, //源文件名
26 D_TargetFileMainName, //目标文件主要名
27 D_TargetFileTempName, //目标文件临时添加名
28 D_TargetFileExtendedName; //目标文件源扩展名
29
30char D_KEY[1024], //File (Decryption or Decrypted) key 文件解密密钥
31 D_KEY2[1024],
32 D_KEY3[1024],
33 D_KEY4[1024];
34/***声明代码-结束 Declare the code - end***/
35
36int RunEncryptFile(const char *E_SourceFileCharPath, char *E_KEY, char *E_KEY2, char *E_KEY3, char *E_KEY4, const char *E_TargetFileCharPath);
37int RunDecryptFile(const char *D_SourceFileCharPath, char *D_KEY, char *D_KEY2, char *D_KEY3, char *D_KEY4, const char *D_TargetFileCharPath);
38
39/*
40
41# ORINIGAL:
42
43This My File Encryption Core Function
44
45Logical method
46
47Use Key
48
49Data /= Key
50Data += Key
51Data *= Key
52Data -= Key
53
54Use Key2
55
56Data *= Key2
57Data -= Key2
58Data /= Key2
59Data += Key2
60
61Use Key3
62
63Data -= Key3
64Data /= Key3
65Data += Key3
66Data *= Key3
67
68Use Key4
69
70Data += Key4
71Data *= Key4
72Data -= Key4
73Data /= Key4
74
75
76
77This My File Decryption Core Function
78
79Logical method
80
81Use Key
82
83Data /= Key
84Data -= Key
85Data *= Key
86Data += Key
87
88Use Key2
89
90Data *= Key
91Data += Key
92Data /= Key
93Data -= Key
94
95Use Key3
96
97Data += Key
98Data /= Key
99Data -= Key
100Data *= Key
101
102Use Key4
103
104Data -= Key
105Data *= Key
106Data += Key
107Data /= Key
108
109# UPDATE:
110
111This My File Encryption Core Function
112
113Logical method
114
115Use Key
116
117Data /= Key
118Data += Key
119Data *= Key
120Data -= Key
121
122Use Key2
123
124Data *= Key2
125Data -= Key2
126Data /= Key2
127Data += Key2
128
129Use Key3
130
131Data -= Key3
132Data /= Key3
133Data += Key3
134Data *= Key3
135
136Use Key4
137
138Data += Key4
139Data *= Key4
140Data -= Key4
141Data /= Key4
142
143
144
145This My File Decryption Core Function
146
147Logical method
148
149Use Key
150
151Data *= Key
152Data -= Key
153Data /= Key
154Data += Key
155
156Use Key2
157
158Data /= Key
159Data += Key
160Data *= Key
161Data -= Key
162
163Use Key3
164
165Data += Key
166Data *= Key
167Data -= Key
168Data /= Key
169
170Use Key4
171
172Data -= Key
173Data /= Key
174Data += Key
175Data *= Key
176
177*/
178
179int NOIEM; //初始加密模块次数 (Number of initial encryption modules)
180int NOIDM; //初始解密模块次数 (Number of initial decryption modules)
181
182int MAX_NOT_E_MODULE = 1281; //加密模块最大循环次数 (The maximum number of times the encryption module is running)
183int MINI_NOT_E_GROUP = 641; //加密集合最小循环次数 (The minimum number of times the encryption group is running)
184
185int MAX_NOT_D_MODULE = 1281; //解密模块最大循环次数 (The maximum number of times the decryption module is running)
186int MINI_NOT_D_GROUP = 641; //解密集合最小循环次数 (The minimum number of times the decryption group is running)
187
188long FileHeaderSignatures = 0;
189long FileHeaderByteData = 0;
190
191size_t seek_cIO_fileEOF(FILE *cIO_streamObject);
192
193size_t seek_cIO_fileEOF(FILE *cIO_streamObject)
194{
195 size_t filePointer_eofPosition;
196
197 fseek(cIO_streamObject, 0L, SEEK_END); //File Content Pointer End Position
198 filePointer_eofPosition = ftell(cIO_streamObject);
199 fseek(cIO_streamObject, 0L, SEEK_SET); //File Content Pointer Begin Position
200
201 return filePointer_eofPosition;
202}
203
204/*******************************************
205* 加密文件
206*
207* E_SourceFileName 需要加密的文件名
208* E_KEY 密钥
209* E_TargetFileNewName 加密完成后要保存的文件名
210
211* @return 加密成功或失败的数字表示
212*
213* 0 = 加密失败
214* 1 = 加密成功
215********************************************/
216
217int RunEncryptFile(const char *E_SourceFileCharPath, char *E_KEY, char *E_KEY2, char *E_KEY3, char *E_KEY4, const char *E_TargetFileCharPath)
218{
219 cin.tie(0);
220 cout.tie(0);
221
222 FILE *FilePointerSource, *FilePointerTarget; //需要打开的文件的指针 Need to open the file MyCharPointer
223 char bufferOriginal[1024] = {'\x00'}; //文件流缓冲区,用于存放从文件读取的数据 File stream bufferOriginal, used to store the data read from the file
224
225 size_t FileReadByte_DataSize, //每次从文件中读取的字节数 The number of bytes read from the file each time
226 RTNOC, //运行循环次数 (Run The Number Of Cycles)
227 KeyLength = getArraySize(E_KEY), //密钥的长度 The length of the key
228 KeyLength2 = getArraySize(E_KEY2),
229 KeyLength3 = getArraySize(E_KEY3),
230 KeyLength4 = getArraySize(E_KEY4);
231
232 FilePointerSource = fopen(E_SourceFileCharPath, "rb"); //以二进制方式读取文件
233 if (FilePointerSource == NULL)
234 {
235 //printf("File[%s]failed to open, please check whether the file path and name are entered correctly !\n", E_SourceFileCharPath);
236 //printf("文件[%s]打开失败,请检查文件路径和名称是否输入正确 !\n", E_SourceFileCharPath);
237 cout << "File "
238 << "[ " << E_SourceFileCharPath << " ]"
239 << " failed to open, please check whether the file path and name are entered correctly!" << endl;
240 cout << "文件 "
241 << "[ " << E_SourceFileCharPath << " ]"
242 << " 打开失败,请检查文件路径和名称是否输入正确 !" << endl;
243 getchar();
244 return RUNTIME_ERROR;
245 }
246
247 FilePointerTarget = fopen(E_TargetFileCharPath, "wb+"); //以二进制方式写入文件
248 if (FilePointerTarget == NULL)
249 {
250 //printf("File[%s]creation/write failed! Please check whether the file path and name are entered correctly !\n", E_TargetFileCharPath);
251 //printf("文件[%s]创建/写入失败!请检查文件路径和名称是否输入正确 !\n", E_TargetFileCharPath);
252 cout << "File "
253 << "[ " << E_TargetFileCharPath << " ]"
254 << " creation/write failed! Please check whether the file path and name are entered correctly !" << endl;
255 cout << "文件 "
256 << "[ " << E_TargetFileCharPath << " ]"
257 << " 创建/写入失败!请检查文件路径和名称是否输入正确 !" << endl;
258 getchar();
259 return RUNTIME_ERROR;
260 }
261
262 /*加密算法开始*/
263
264 /*****************************************************************************bufferOriginal[RTNOC]******************************************************************************/
265
266 //运行大型加密模块
267 //Run large encryption module
268
269 //文件和密钥在缓冲区中计算
270 //The file and key are counted in Buffer
271
272 /*Skip file header (128 byte)*/
273 fseek(FilePointerSource, 128L, SEEK_SET); //Move the file MyCharPointer to the 128th byte of the file start
274 FileHeaderSignatures = ftell(FilePointerSource); //Get this file header length
275 fseek(FilePointerSource, 0L, SEEK_SET); //Move the file MyCharPointer to this file start point
276
277 /*Continuously read fileheadersignatures length data from file, save to bufferOriginal until end of file*/
278 while ((FileHeaderByteData = fread(bufferOriginal, 1, FileHeaderSignatures, FilePointerSource)) > 0)
279 {
280 fwrite(bufferOriginal, 1, FileHeaderByteData, FilePointerTarget); //Write data from bufferOriginal to file
281 }
282
283 /*The MyCharPointer to the file stream is moved, and the read and write data continues to start at the 128rd byte*/
284 fseek(FilePointerSource, 129L, SEEK_SET);
285 fseek(FilePointerTarget, 129L, SEEK_SET);
286
287 static array<my_uint, 1024> Decimal_FileBufferArray;
288 Decimal_FileBufferArray.fill(0);
289 static array<my_byte, 1024> ByteArray_FileBuffer;
290 ByteArray_FileBuffer.fill('\xff');
291
292 static array<my_uint, 1024> Decimal_Keys; //passwords for encryption processing
293
294 static array<my_uint, 1024> Decimal_KeyArray;
295 static array<my_uint, 1024> Decimal_KeyArray2;
296 static array<my_uint, 1024> Decimal_KeyArray3;
297 static array<my_uint, 1024> Decimal_KeyArray4;
298
299 my_byte myBuffer_byteArray[1024] = {"0xff"}; //converted type data of file buffer
300 my_byte myBuffer_byteArray2[1024] = {"0xff"};
301
302 //my_byte* myBuffer_byteArray = nullptr;
303 //my_byte* myBuffer_byteArray2 = nullptr;
304
305 for (NOIEM = 0; NOIEM < MAX_NOT_E_MODULE; NOIEM++)
306 {
307 system("cls");
308 double currentWorkMainProgress = NOIEM / (((MAX_NOT_E_MODULE - 1) / 100) * 1);
309 cout << "Encrypting Progress = " << currentWorkMainProgress << "%" << endl;
310 system("@color 6F");
311 cout << "Please wait, read and write in the file......" << endl;
312 cout << "请等待,文件读写中......" << endl;
313 system("@color 0D");
314 cout << "The display of the interaction progress has been opened using the request for the encryption function." << endl;
315 cout << "使用加密功能的请求,交互进度的显示已经被打开。" << endl;
316 cout << "Encrypting...... Currently in use the first key" << endl;
317
318 my_l_sint FileAccessPointer_Source = ftell(FilePointerSource);
319 size_t FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
320
321 for (NOIEM = 0; NOIEM < MINI_NOT_E_GROUP; NOIEM++)
322 {
323 //Mini-Group Encryption Module Key1-Calculate1
324 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //Constantly reads KeyLength-length data from a file, saves it to the bufferOriginal until the end of the file. 不断地从文件中读取 KeyLength 长度的数据,保存到buffer,直到文件结束。
325 {
326 FileAccessPointer_Source = ftell(FilePointerSource);
327 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
328
329 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength, FilePointerSource);
330
331 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
332 {
333 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
334 }
335 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
336 {
337 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(E_KEY[RTNOC]);
338 }
339
340 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
341 //signedChar_convertionToUnsignedChar<char,my_byte>(E_KEY, myBuffer_byteArray2);
342
343 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
344 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(E_KEY);
345
346 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
347 {
348 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the encryption." << endl;
349 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
350 }
351 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
352 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
353 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
354 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
355 cout << "Current hexdecimal temporary bufferOriginal is :\n"
356 << byteHexadecimal_string << endl;
357 cout << "Current decimal file bufferOriginal is :\n"
358 << fileBuffer_decimalString << std::dec << endl;
359 dataString.clear();
360 byteHexadecimal_string.clear();
361 fileBuffer_decimalString.clear();
362
363 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
364 {
365 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of encryption key 1 ." << endl;
366 Decimal_KeyArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
367 }
368 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
369 string fileKey_decimalString, keyHexadecimal_string, dataString;
370 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
371 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray[RTNOC]));
372 cout << "Current hexdecimal temporary key is :\n"
373 << keyHexadecimal_string << endl;
374 cout << "Current decimal file key is :\n"
375 << fileKey_decimalString << endl;
376 dataString.clear();
377 keyHexadecimal_string.clear();
378 fileKey_decimalString.clear();
379 cout << "Current encipher integer key one is : " << Decimal_KeyArray[RTNOC] << endl;
380
381 try
382 {
383 /* Tracking code */
384
385 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
386 {
387 for (RTNOC = 0; RTNOC < Decimal_KeyArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
388 {
389 Decimal_Keys[RTNOC] = Decimal_KeyArray[RTNOC % KeyLength];
390 }
391
392 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
393 {
394 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
395 }
396
397 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop division) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递除运算.
398 {
399
400 if (Decimal_KeyArray[RTNOC] == 0)
401 {
402 RTNOC += 1;
403 }
404 else if (Decimal_KeyArray[RTNOC] != 0)
405 {
406 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray[RTNOC] == 0)
407 {
408 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
409 }
410 }
411 }
412
413 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
414 {
415 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
416 }
417
418 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop addition) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递增运算.
419 {
420 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
421 }
422
423 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
424 {
425 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
426 }
427
428 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop multiplication) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递乘运算.
429 {
430 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
431 }
432
433 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
434 {
435 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
436 }
437
438 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop subtraction) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递减运算.
439 {
440 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
441 }
442
443 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
444 {
445 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
446 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
447 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
448
449 myBuffer_byteArray[1024] = {0x00};
450 myBuffer_byteArray2[1024] = {0x00};
451 }
452 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
453 }
454 }
455 catch (const exception &except_massage)
456 {
457 std::cout << except_massage.what() << std::endl;
458 }
459 }
460 fseek(FilePointerSource, 0L, SEEK_SET);
461 fseek(FilePointerTarget, 0L, SEEK_SET);
462 }
463
464 //文件和密钥2在缓冲区中计算
465 //The file and key2 are counted in Buffer
466
467 cout << "Encrypting...... Currently in use the second key" << endl;
468
469 //Mini-Group Encryption Module Key2-Calculate1
470 for (NOIEM = 0; NOIEM < MINI_NOT_E_GROUP; NOIEM++)
471 {
472 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //Constantly reads KeyLength-length data from a file, saves it to the bufferOriginal until the end of the file. 不断地从文件中读取 KeyLength 长度的数据,保存到buffer,直到文件结束。
473 {
474 FileAccessPointer_Source = ftell(FilePointerSource);
475 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
476
477 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength2, FilePointerSource);
478
479 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
480 {
481 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
482 }
483 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
484 {
485 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(E_KEY2[RTNOC]);
486 }
487
488 //signedChar_convertionToUnsignedChar<char, my_byte>(bufferOriginal, myBuffer_byteArray);
489 //signedChar_convertionToUnsignedChar<char, my_byte>(E_KEY2, myBuffer_byteArray2);
490
491 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
492 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(E_KEY2);
493
494 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
495 {
496 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the encryption." << endl;
497 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
498 }
499 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
500 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
501 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
502 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
503 cout << "Current hexdecimal temporary bufferOriginal is :\n"
504 << byteHexadecimal_string << endl;
505 cout << "Current decimal file bufferOriginal is :\n"
506 << fileBuffer_decimalString << std::dec << endl;
507 dataString.clear();
508 byteHexadecimal_string.clear();
509 fileBuffer_decimalString.clear();
510
511 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
512 {
513 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of encryption key 2 ." << endl;
514 Decimal_KeyArray2[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
515 }
516 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
517 string fileKey_decimalString, keyHexadecimal_string, dataString;
518 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
519 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray2[RTNOC]));
520 cout << "Current hexdecimal temporary key is :\n"
521 << keyHexadecimal_string << endl;
522 cout << "Current decimal file key is :\n"
523 << fileKey_decimalString << endl;
524 dataString.clear();
525 keyHexadecimal_string.clear();
526 fileKey_decimalString.clear();
527 cout << "Current encipher integer key two is : " << Decimal_KeyArray2[RTNOC] << endl;
528
529 try
530 {
531 /* Tracking code */
532
533 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
534 {
535 for (RTNOC = 0; RTNOC < Decimal_KeyArray2.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
536 {
537 Decimal_Keys[RTNOC] = Decimal_KeyArray2[RTNOC % KeyLength2];
538 }
539
540 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
541 {
542 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray2[RTNOC];
543 }
544
545 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop multiplication) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递乘运算.
546 {
547 Decimal_FileBufferArray[RTNOC] *= Decimal_KeyArray2[RTNOC];
548 }
549
550 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
551 {
552 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray2[RTNOC];
553 }
554
555 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop subtraction) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递减运算.
556 {
557 Decimal_FileBufferArray[RTNOC] -= Decimal_KeyArray2[RTNOC];
558 }
559
560 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
561 {
562 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray2[RTNOC];
563 }
564
565 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop division) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递除运算。
566 {
567 if (Decimal_KeyArray2[RTNOC] == 0)
568 {
569 RTNOC += 1;
570 }
571 else if (Decimal_KeyArray2[RTNOC] != 0)
572 {
573 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray2[RTNOC] == 0)
574 {
575 Decimal_FileBufferArray[RTNOC] /= Decimal_KeyArray2[RTNOC];
576 }
577 }
578 }
579
580 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
581 {
582 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray2[RTNOC];
583 }
584
585 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop addition) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递增运算.
586 {
587 Decimal_FileBufferArray[RTNOC] += Decimal_KeyArray2[RTNOC];
588 }
589
590 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
591 {
592 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
593 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
594 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
595
596 myBuffer_byteArray[1024] = {0x00};
597 myBuffer_byteArray2[1024] = {0x00};
598 }
599 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
600 }
601 }
602 catch (const exception &except_massage)
603 {
604 std::cout << except_massage.what() << std::endl;
605 }
606 }
607 fseek(FilePointerSource, 0L, SEEK_SET);
608 fseek(FilePointerTarget, 0L, SEEK_SET);
609 }
610
611 //文件和密钥3在缓冲区中计算
612 //The file and key3 are counted in Buffer
613
614 cout << "Encrypting...... Currently in use the third key" << endl;
615
616 //Mini-Group Encryption Module Key3-Calculate1
617 for (NOIEM = 0; NOIEM < MINI_NOT_E_GROUP; NOIEM++)
618 {
619
620 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //Constantly reads KeyLength-length data from a file, saves it to the bufferOriginal until the end of the file. 不断地从文件中读取 KeyLength 长度的数据,保存到buffer,直到文件结束。
621 {
622 FileAccessPointer_Source = ftell(FilePointerSource);
623 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
624
625 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength3, FilePointerSource);
626
627 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
628 {
629 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
630 }
631 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
632 {
633 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(E_KEY3[RTNOC]);
634 }
635
636 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
637 //signedChar_convertionToUnsignedChar<char,my_byte>(E_KEY3, myBuffer_byteArray2);
638
639 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
640 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(E_KEY3);
641
642 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
643 {
644 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the encryption." << endl;
645 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
646 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
647
648 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
649 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
650 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
651 cout << "Current hexdecimal temporary bufferOriginal is :\n"
652 << byteHexadecimal_string << endl;
653 cout << "Current decimal file bufferOriginal is :\n"
654 << fileBuffer_decimalString << std::dec << endl;
655 dataString.clear();
656 byteHexadecimal_string.clear();
657 fileBuffer_decimalString.clear();
658 }
659
660 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
661 {
662 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of encryption key 3 ." << endl;
663 Decimal_KeyArray3[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
664 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
665
666 string fileKey_decimalString, keyHexadecimal_string, dataString;
667 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
668 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray3[RTNOC]));
669 cout << "Current hexdecimal temporary key is :\n"
670 << keyHexadecimal_string << endl;
671 cout << "Current decimal file key is :\n"
672 << fileKey_decimalString << endl;
673 dataString.clear();
674 keyHexadecimal_string.clear();
675 fileKey_decimalString.clear();
676 cout << "Current encipher integer key three is : " << Decimal_KeyArray3[RTNOC] << endl;
677 }
678
679 try
680 {
681 /* Tracking code */
682
683 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
684 {
685 for (RTNOC = 0; RTNOC < Decimal_KeyArray3.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
686 {
687 Decimal_Keys[RTNOC] = Decimal_KeyArray3[RTNOC % KeyLength3];
688 }
689
690 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
691 {
692 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray3[RTNOC];
693 }
694
695 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop subtraction) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递减运算.
696 {
697 Decimal_FileBufferArray[RTNOC] -= Decimal_KeyArray3[RTNOC];
698 }
699
700 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
701 {
702 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray3[RTNOC];
703 }
704
705 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop division) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递除运算.
706 {
707 if (Decimal_KeyArray3[RTNOC] == 0)
708 {
709 RTNOC += 1;
710 }
711 else if (Decimal_KeyArray3[RTNOC] != 0)
712 {
713 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray3[RTNOC] == 0)
714 {
715 Decimal_FileBufferArray[RTNOC] /= Decimal_KeyArray3[RTNOC];
716 }
717 }
718 }
719
720 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
721 {
722 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray3[RTNOC];
723 }
724
725 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop addition) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递增运算.
726 {
727 Decimal_FileBufferArray[RTNOC] += Decimal_KeyArray3[RTNOC];
728 }
729
730 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
731 {
732 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray3[RTNOC];
733 }
734
735 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop multiplication) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递乘运算.
736 {
737 Decimal_FileBufferArray[RTNOC] *= Decimal_KeyArray3[RTNOC];
738 }
739
740 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
741 {
742 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
743 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
744 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
745
746 myBuffer_byteArray[1024] = {0x00};
747 myBuffer_byteArray2[1024] = {0x00};
748 }
749 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
750 }
751 }
752 catch (const exception &except_massage)
753 {
754 std::cout << except_massage.what() << std::endl;
755 }
756 }
757 fseek(FilePointerSource, 0L, SEEK_SET);
758 fseek(FilePointerTarget, 0L, SEEK_SET);
759 }
760
761 //文件和密钥4在缓冲区中计算
762 //The file and key4 are counted in Buffer
763
764 cout << "Encrypting...... Currently in use the fourth key" << endl;
765
766 //Mini-Group Encryption Module Key4-Calculate1
767
768 for (NOIEM = 0; NOIEM < MINI_NOT_E_GROUP; NOIEM++)
769 {
770 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //Constantly reads KeyLength-length data from a file, saves it to the bufferOriginal until the end of the file. 不断地从文件中读取 KeyLength 长度的数据,保存到buffer,直到文件结束。
771 {
772 FileAccessPointer_Source = ftell(FilePointerSource);
773 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
774
775 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength4, FilePointerSource);
776
777 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
778 {
779 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
780 }
781 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
782 {
783 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(E_KEY4[RTNOC]);
784 }
785
786 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
787 //signedChar_convertionToUnsignedChar<char,my_byte>(E_KEY4, myBuffer_byteArray2)
788
789 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
790 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(E_KEY4);
791
792 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
793 {
794 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the encryption." << endl;
795 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
796 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
797
798 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
799 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
800 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
801 cout << "Current hexdecimal temporary bufferOriginal is :\n"
802 << byteHexadecimal_string << endl;
803 cout << "Current decimal file bufferOriginal is :\n"
804 << fileBuffer_decimalString << std::dec << endl;
805 dataString.clear();
806 byteHexadecimal_string.clear();
807 fileBuffer_decimalString.clear();
808 }
809
810 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
811 {
812 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of encryption key 4 ." << endl;
813 Decimal_KeyArray4[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
814 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
815
816 string fileKey_decimalString, keyHexadecimal_string, dataString;
817 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
818 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray4[RTNOC]));
819 cout << "Current hexdecimal temporary key is :\n"
820 << keyHexadecimal_string << endl;
821 cout << "Current decimal file key is :\n"
822 << fileKey_decimalString << endl;
823 dataString.clear();
824 keyHexadecimal_string.clear();
825 fileKey_decimalString.clear();
826 cout << "Current encipher integer key four is : " << Decimal_KeyArray4[RTNOC] << endl;
827 }
828
829 try
830 {
831 /* Tracking code */
832
833 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
834 {
835 for (RTNOC = 0; RTNOC < Decimal_KeyArray4.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
836 {
837 Decimal_Keys[RTNOC] = Decimal_KeyArray4[RTNOC % KeyLength4];
838 }
839
840 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
841 {
842 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray4[RTNOC];
843 }
844
845 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop addition) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递增运算.
846 {
847 Decimal_FileBufferArray[RTNOC] += Decimal_KeyArray4[RTNOC];
848 }
849
850 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
851 {
852 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray4[RTNOC];
853 }
854
855 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop multiplication) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递乘运算.
856 {
857 Decimal_FileBufferArray[RTNOC] *= Decimal_KeyArray4[RTNOC];
858 }
859
860 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
861 {
862 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray4[RTNOC];
863 }
864
865 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop subtraction) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递减运算.
866 {
867 Decimal_FileBufferArray[RTNOC] -= Decimal_KeyArray4[RTNOC];
868 }
869
870 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
871 {
872 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray4[RTNOC];
873 }
874
875 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop division) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和Decimal_KeyArray进行递除运算.
876 {
877 if (Decimal_KeyArray4[RTNOC] == 0)
878 {
879 RTNOC += 1;
880 }
881 if (Decimal_KeyArray4[RTNOC] != 0)
882 {
883 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray4[RTNOC] == 0)
884 {
885 Decimal_FileBufferArray[RTNOC] /= Decimal_KeyArray4[RTNOC];
886 }
887 }
888 }
889
890 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
891 {
892 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
893 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
894 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
895
896 myBuffer_byteArray[1024] = {0x00};
897 myBuffer_byteArray2[1024] = {0x00};
898 }
899 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
900 }
901 }
902 catch (const exception &except_massage)
903 {
904 std::cout << except_massage.what() << std::endl;
905 }
906 }
907 fseek(FilePointerSource, 0L, SEEK_SET);
908 fseek(FilePointerTarget, 0L, SEEK_SET);
909 }
910
911 system("@color 07");
912
913 if (NOIEM < MAX_NOT_E_MODULE || NOIEM == 12800)
914 {
915 cout << "The display of the interaction progress has been closed for the encryption function." << endl;
916 cout << "已经关闭加密功能的交互进度的显示。" << endl;
917 break; //End encrypting process
918 }
919 else
920 {
921 NOIEM = 0;
922 fclose(FilePointerSource);
923 fclose(FilePointerTarget);
924 return FAILED;
925 }
926 }
927
928 /***********************************************************************************************************************************************************/
929
930 /*加密算法结束*/
931
932 fclose(FilePointerSource);
933 fclose(FilePointerTarget);
934
935 //DeleteFile(E_SourceFileCharPath); /*This is windows API function*/
936 //remove(E_SourceFileCharPath); /*This is C & C++ language the delete file common IO function, use in the linux and unix or windows platform.*/
937
938 return SUCCESSFUL;
939}
940
941/*******************************************
942* 解密文件
943*
944* D_SourceFileName 需要解密的文件名
945* D_KEY 密钥
946* D_TargetFileNewName 解密完成后要保存的文件名
947*
948* @return 解密成功或失败的数字表示
949*
950* 0 = 解密失败
951* 1 = 解密成功
952********************************************/
953
954int RunDecryptFile(const char *D_SourceFileCharPath, char *D_KEY, char *D_KEY2, char *D_KEY3, char *D_KEY4, const char *D_TargetFileCharPath)
955{
956 cin.tie(0);
957 cout.tie(0);
958
959 FILE *FilePointerSource, *FilePointerTarget; //需要打开的文件的指针 Need to open the file MyCharPointer
960 char bufferOriginal[1024] = {'\x00'}; //文件流缓冲区,用于存放从文件读取的数据 File stream bufferOriginal, used to store the data read from the file
961
962 size_t FileReadByte_DataSize, //每次从文件中读取的字节数 The number of bytes read from the file each time
963 RTNOC, //运行循环次数 (Run The Number Of Cycles)
964 KeyLength = getArraySize(D_KEY), //密钥的长度 The length of the key
965 KeyLength2 = getArraySize(D_KEY2),
966 KeyLength3 = getArraySize(D_KEY3),
967 KeyLength4 = getArraySize(D_KEY4);
968
969 FilePointerSource = fopen(D_SourceFileCharPath, "rb"); //以二进制方式读取文件
970 if (FilePointerSource == NULL)
971 {
972 //printf("File[%s]failed to open, please check whether the file path and name are entered correctly !\n", D_SourceFileCharPath);
973 //printf("文件[%s]打开失败,请检查文件路径和名称是否输入正确 !\n", D_SourceFileCharPath);
974 cout << "File "
975 << "[ " << D_SourceFileCharPath << " ]"
976 << " failed to open, please check whether the file path and name are entered correctly !" << endl;
977 cout << "文件 "
978 << "[ " << D_SourceFileCharPath << " ]"
979 << " 打开失败,请检查文件路径和名称是否输入正确 !" << endl;
980 getchar();
981 return RUNTIME_ERROR;
982 }
983
984 FilePointerTarget = fopen(D_TargetFileCharPath, "wb+"); //以二进制方式写入文件
985 if (FilePointerTarget == NULL)
986 {
987 //printf("File[%s]creation/write failed! Please check whether the file path and name are entered correctly !\n", D_TargetFileCharPath);
988 //printf("文件[%s]创建/写入失败!请检查文件路径和名称是否输入正确 !\n", D_TargetFileCharPath);
989 cout << "File "
990 << "[ " << D_TargetFileCharPath << " ]"
991 << " creation/write failed! Please check whether the file path and name are entered correctly !" << endl;
992 cout << "文件 "
993 << "[ " << D_TargetFileCharPath << " ]"
994 << " 创建/写入失败!请检查文件路径和名称是否输入正确 !" << endl;
995 getchar();
996 return RUNTIME_ERROR;
997 }
998
999 /*解密算法开始*/
1000
1001 /***********************************************************************************************************************************************************/
1002
1003 //运行大型解密模块
1004 //Run large decryption module
1005
1006 //文件和密钥在缓冲区中计算
1007 //The file and key are counted in Buffer
1008
1009 /*Skip file header (128 byte)*/
1010 fseek(FilePointerSource, 128L, SEEK_SET); //Move the file MyCharPointer to the 128th byte of the file start
1011 FileHeaderSignatures = ftell(FilePointerSource); //Get this file header length
1012 fseek(FilePointerSource, 0L, SEEK_SET); //Move the file MyCharPointer to this file start point
1013
1014 /*Continuously read fileheadersignatures length data from file, save to bufferOriginal until end of file*/
1015 while ((FileHeaderByteData = fread(bufferOriginal, 1, FileHeaderSignatures, FilePointerSource)) > 0)
1016 {
1017 fwrite(bufferOriginal, 1, FileHeaderByteData, FilePointerTarget); //Write data from bufferOriginal to file
1018 }
1019
1020 /*The MyCharPointer to the file stream is moved, and the read and write data continues to start at the 128rd byte*/
1021 fseek(FilePointerSource, 129L, SEEK_SET);
1022 fseek(FilePointerTarget, 129L, SEEK_SET);
1023
1024 static array<my_uint, 1024> Decimal_FileBufferArray;
1025 Decimal_FileBufferArray.fill(0);
1026 static array<my_byte, 1024> ByteArray_FileBuffer;
1027 ByteArray_FileBuffer.fill('\xff');
1028
1029 static array<my_uint, 1024> Decimal_Keys; //paswords for decryption processing
1030
1031 static array<my_uint, 1024> Decimal_KeyArray;
1032 static array<my_uint, 1024> Decimal_KeyArray2;
1033 static array<my_uint, 1024> Decimal_KeyArray3;
1034 static array<my_uint, 1024> Decimal_KeyArray4;
1035
1036 my_byte myBuffer_byteArray[1024] = {0xff}; //converted type data of file buffer
1037 my_byte myBuffer_byteArray2[1024] = {0xff};
1038
1039 //my_byte* myBuffer_byteArray = nullptr;
1040 //my_byte* myBuffer_byteArray2 = nullptr;
1041
1042 for (NOIDM = 0; NOIDM < MAX_NOT_D_MODULE; NOIDM++)
1043 {
1044 system("cls");
1045 double currentWorkMainProgress = NOIDM / (((MAX_NOT_D_MODULE - 1) / 100) * 1);
1046 cout << "Decrypting Progress = " << currentWorkMainProgress << "%" << endl;
1047 system("@color 6F");
1048 std::cout << "Please wait, read and write in the file......" << endl;
1049 std::cout << "请等待,文件读写中......" << endl;
1050 system("@color 0D");
1051 cout << "The display of the interaction progress has been opened using the request for the decryption function." << endl;
1052 cout << "使用解密功能的请求,交互进度的显示已经被打开。" << endl;
1053 cout << "Decrypting...... Currently in use the first key" << endl;
1054
1055 my_l_sint FileAccessPointer_Source = ftell(FilePointerSource);
1056 size_t FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1057
1058 //Mini-Group Decryption Module Key1-Calculate1
1059 for (NOIDM = 0; NOIDM < MINI_NOT_D_GROUP; NOIDM++)
1060 {
1061 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //Constantly reads KeyLength-length data from a file, saves it to the bufferOriginal until the end of the file. 不断地从文件中读取 KeyLength 长度的数据,保存到buffer,直到文件结束。
1062 {
1063 FileAccessPointer_Source = ftell(FilePointerSource);
1064 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1065
1066 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength, FilePointerSource);
1067
1068 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1069 {
1070 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
1071 }
1072 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1073 {
1074 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(D_KEY[RTNOC]);
1075 }
1076
1077 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
1078 //signedChar_convertionToUnsignedChar<char,my_byte>(D_KEY, myBuffer_byteArray2);
1079
1080 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
1081 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(D_KEY);
1082
1083 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
1084 {
1085 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the decryption." << endl;
1086 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
1087 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
1088
1089 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
1090 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1091 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
1092 cout << "Current hexdecimal temporary bufferOriginal is :\n"
1093 << byteHexadecimal_string << endl;
1094 cout << "Current decimal file bufferOriginal is :\n"
1095 << fileBuffer_decimalString << std::dec << endl;
1096 dataString.clear();
1097 byteHexadecimal_string.clear();
1098 fileBuffer_decimalString.clear();
1099 }
1100
1101 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
1102 {
1103 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of decryption key 1 ." << endl;
1104 Decimal_KeyArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
1105 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
1106
1107 string fileKey_decimalString, keyHexadecimal_string, dataString;
1108 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1109 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray[RTNOC]));
1110 cout << "Current hexdecimal temporary key is :\n"
1111 << keyHexadecimal_string << endl;
1112 cout << "Current decimal file key is :\n"
1113 << fileKey_decimalString << endl;
1114 dataString.clear();
1115 keyHexadecimal_string.clear();
1116 fileKey_decimalString.clear();
1117 cout << "Current decipher integer key one is : " << Decimal_KeyArray[RTNOC] << endl;
1118 }
1119
1120 try
1121 {
1122 /* Tracking code */
1123
1124 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
1125 {
1126 for (RTNOC = 0; RTNOC < Decimal_KeyArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1127 {
1128 Decimal_Keys[RTNOC] = Decimal_KeyArray[RTNOC % KeyLength];
1129 }
1130
1131 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1132 {
1133 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1134 }
1135
1136 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop division) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递除运算.
1137 {
1138 if (Decimal_KeyArray[RTNOC] == 0)
1139 {
1140 RTNOC += 1;
1141 }
1142 else if (Decimal_KeyArray[RTNOC] != 0)
1143 {
1144 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray[RTNOC] == 0)
1145 {
1146 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
1147 }
1148 }
1149 }
1150
1151 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1152 {
1153 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1154 }
1155
1156 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop subtraction) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递减运算.
1157 {
1158 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
1159 }
1160
1161 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1162 {
1163 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1164 }
1165
1166 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop multiplication) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递乘运算.
1167 {
1168 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
1169 }
1170
1171 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1172 {
1173 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1174 }
1175
1176 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop addition) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递增运算.
1177 {
1178 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
1179 }
1180
1181 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
1182 {
1183 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
1184 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
1185 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
1186
1187 myBuffer_byteArray[1024] = {0x00};
1188 myBuffer_byteArray2[1024] = {0x00};
1189 }
1190 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
1191 }
1192 }
1193 catch (const exception &except_massage)
1194 {
1195 std::cout << except_massage.what() << std::endl;
1196 }
1197 }
1198 fseek(FilePointerSource, 0L, SEEK_SET);
1199 fseek(FilePointerTarget, 0L, SEEK_SET);
1200 }
1201
1202 //文件和密钥2在缓冲区中计算
1203 //The file and key2 are counted in Buffer
1204
1205 cout << "Decrypting...... Currently in use the second key" << endl;
1206
1207 //Mini-Group Decryption Module Key2-Calculate1
1208 for (NOIDM = 0; NOIDM < MINI_NOT_D_GROUP; NOIDM++)
1209 {
1210 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //不断地从文件中读取 KeyLength2 长度的数据,保存到buffer,直到文件结束
1211 {
1212 FileAccessPointer_Source = ftell(FilePointerSource);
1213 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1214
1215 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength2, FilePointerSource);
1216
1217 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1218 {
1219 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
1220 }
1221 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1222 {
1223 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(D_KEY2[RTNOC]);
1224 }
1225
1226 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
1227 //signedChar_convertionToUnsignedChar<char,my_byte>(D_KEY2, myBuffer_byteArray2);
1228
1229 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
1230 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(D_KEY2);
1231
1232 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
1233 {
1234 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the decryption." << endl;
1235 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
1236 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
1237
1238 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
1239 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1240 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
1241 cout << "Current hexdecimal temporary bufferOriginal is :\n"
1242 << byteHexadecimal_string << endl;
1243 cout << "Current decimal file bufferOriginal is :\n"
1244 << fileBuffer_decimalString << std::dec << endl;
1245 dataString.clear();
1246 byteHexadecimal_string.clear();
1247 fileBuffer_decimalString.clear();
1248 }
1249
1250 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
1251 {
1252 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of decryption key 2 ." << endl;
1253 Decimal_KeyArray2[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
1254 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
1255
1256 string fileKey_decimalString, keyHexadecimal_string, dataString;
1257 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1258 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray2[RTNOC]));
1259 cout << "Current hexdecimal temporary key is :\n"
1260 << keyHexadecimal_string << endl;
1261 cout << "Current decimal file key is :\n"
1262 << fileKey_decimalString << endl;
1263 dataString.clear();
1264 keyHexadecimal_string.clear();
1265 fileKey_decimalString.clear();
1266 cout << "Current decipher integer key two is : " << Decimal_KeyArray2[RTNOC] << endl;
1267 }
1268
1269 try
1270 {
1271 /* Tracking code */
1272
1273 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
1274 {
1275 for (RTNOC = 0; RTNOC < Decimal_KeyArray2.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1276 {
1277 Decimal_Keys[RTNOC] = Decimal_KeyArray2[RTNOC % KeyLength2];
1278 }
1279
1280 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1281 {
1282 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1283 }
1284
1285 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop multiplication) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递乘运算.
1286 {
1287 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
1288 }
1289
1290 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1291 {
1292 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1293 }
1294
1295 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop addition) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递增运算.
1296 {
1297 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
1298 }
1299
1300 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1301 {
1302 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1303 }
1304
1305 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop division) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递除运算.
1306 {
1307 if (Decimal_KeyArray2[RTNOC] == 0)
1308 {
1309 RTNOC += 1;
1310 }
1311 else if (Decimal_KeyArray2[RTNOC] != 0)
1312 {
1313 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray2[RTNOC] == 0)
1314 {
1315 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
1316 }
1317 }
1318 }
1319
1320 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1321 {
1322 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1323 }
1324
1325 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop subtraction) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递减运算.
1326 {
1327 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
1328 }
1329
1330 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
1331 {
1332 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
1333 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
1334 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
1335
1336 myBuffer_byteArray[1024] = {0x00};
1337 myBuffer_byteArray2[1024] = {0x00};
1338 }
1339 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
1340 }
1341 }
1342 catch (const exception &except_massage)
1343 {
1344 std::cout << except_massage.what() << std::endl;
1345 }
1346 }
1347 fseek(FilePointerSource, 0L, SEEK_SET);
1348 fseek(FilePointerTarget, 0L, SEEK_SET);
1349 }
1350
1351 //文件和密钥3在缓冲区中计算
1352 //The file and key3 are counted in Buffer
1353
1354 cout << "Decrypting...... Currently in use the third key" << endl;
1355
1356 //Mini-Group Decryption Module Key3-Calculate1
1357 for (NOIDM = 0; NOIDM < MINI_NOT_D_GROUP; NOIDM++)
1358 {
1359 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //不断地从文件中读取 KeyLength3 长度的数据,保存到buffer,直到文件结束
1360 {
1361 FileAccessPointer_Source = ftell(FilePointerSource);
1362 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1363
1364 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength3, FilePointerSource);
1365
1366 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1367 {
1368 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
1369 }
1370 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1371 {
1372 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(D_KEY3[RTNOC]);
1373 }
1374
1375 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
1376 //signedChar_convertionToUnsignedChar<char,my_byte>(D_KEY3, myBuffer_byteArray2);
1377
1378 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
1379 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(D_KEY3);
1380
1381 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
1382 {
1383 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the decryption." << endl;
1384 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
1385 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
1386
1387 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
1388 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1389 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
1390 cout << "Current hexdecimal temporary bufferOriginal is :\n"
1391 << byteHexadecimal_string << endl;
1392 cout << "Current decimal file bufferOriginal is :\n"
1393 << fileBuffer_decimalString << std::dec << endl;
1394 dataString.clear();
1395 byteHexadecimal_string.clear();
1396 fileBuffer_decimalString.clear();
1397 }
1398
1399 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
1400 {
1401 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of decryption key 3 ." << endl;
1402 Decimal_KeyArray3[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
1403 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
1404
1405 string fileKey_decimalString, keyHexadecimal_string, dataString;
1406 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1407 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray3[RTNOC]));
1408 cout << "Current hexdecimal temporary key is :\n"
1409 << keyHexadecimal_string << endl;
1410 cout << "Current decimal file key is :\n"
1411 << fileKey_decimalString << endl;
1412 dataString.clear();
1413 keyHexadecimal_string.clear();
1414 fileKey_decimalString.clear();
1415 cout << "Current decipher integer key three is : " << Decimal_KeyArray3[RTNOC] << endl;
1416 }
1417
1418 try
1419 {
1420 /* Tracking code */
1421
1422 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
1423 {
1424 for (RTNOC = 0; RTNOC < Decimal_KeyArray3.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1425 {
1426 Decimal_Keys[RTNOC] = Decimal_KeyArray3[RTNOC % KeyLength3];
1427 }
1428
1429 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1430 {
1431 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1432 }
1433
1434 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop addition) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递增运算.
1435 {
1436 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
1437 }
1438
1439 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1440 {
1441 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1442 }
1443
1444 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop division) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递除运算.
1445 {
1446 if (Decimal_KeyArray3[RTNOC] == 0)
1447 {
1448 RTNOC += 1;
1449 }
1450 else if (Decimal_KeyArray3[RTNOC] != 0)
1451 {
1452 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray3[RTNOC] == 0)
1453 {
1454 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
1455 }
1456 }
1457 }
1458
1459 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1460 {
1461 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1462 }
1463
1464 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop subtraction) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递减运算.
1465 {
1466 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
1467 }
1468
1469 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1470 {
1471 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1472 }
1473
1474 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop multiplication) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递乘运算.
1475 {
1476 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
1477 }
1478
1479 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
1480 {
1481 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
1482 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
1483 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
1484
1485 myBuffer_byteArray[1024] = {0x00};
1486 myBuffer_byteArray2[1024] = {0x00};
1487 }
1488 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
1489 }
1490 }
1491 catch (const exception &except_massage)
1492 {
1493 std::cout << except_massage.what() << std::endl;
1494 }
1495 }
1496 fseek(FilePointerSource, 0L, SEEK_SET);
1497 fseek(FilePointerTarget, 0L, SEEK_SET);
1498 }
1499
1500 //文件和密钥4在缓冲区中计算
1501 //The file and key4 are counted in Buffer
1502
1503 cout << "Decrypting...... Currently in use the fourth key" << endl;
1504
1505 //Mini-Group Decryption Module Key4-Calculate1
1506 for (NOIDM = 0; NOIDM < MINI_NOT_D_GROUP; NOIDM++)
1507 {
1508 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //不断地从文件中读取 KeyLength4 长度的数据,保存到buffer,直到文件结束
1509 {
1510 FileAccessPointer_Source = ftell(FilePointerSource);
1511 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1512
1513 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength4, FilePointerSource);
1514
1515 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1516 {
1517 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
1518 }
1519 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1520 {
1521 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(D_KEY4[RTNOC]);
1522 }
1523
1524 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
1525 //signedChar_convertionToUnsignedChar<char,my_byte>(D_KEY4, myBuffer_byteArray2);
1526
1527 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
1528 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(D_KEY4);
1529
1530 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
1531 {
1532 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the decryption." << endl;
1533 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
1534 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
1535
1536 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
1537 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1538 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
1539 cout << "Current hexdecimal temporary bufferOriginal is :\n"
1540 << byteHexadecimal_string << endl;
1541 cout << "Current decimal file bufferOriginal is :\n"
1542 << fileBuffer_decimalString << std::dec << endl;
1543 dataString.clear();
1544 byteHexadecimal_string.clear();
1545 fileBuffer_decimalString.clear();
1546 }
1547
1548 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
1549 {
1550 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of decryption key 4 ." << endl;
1551 Decimal_KeyArray4[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
1552 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
1553
1554 string fileKey_decimalString, keyHexadecimal_string, dataString;
1555 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1556 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray4[RTNOC]));
1557 cout << "Current hexdecimal temporary key is :\n"
1558 << keyHexadecimal_string << endl;
1559 cout << "Current decimal file key is :\n"
1560 << fileKey_decimalString << endl;
1561 dataString.clear();
1562 keyHexadecimal_string.clear();
1563 fileKey_decimalString.clear();
1564 cout << "Current decipher integer key four is : " << Decimal_KeyArray[RTNOC] << endl;
1565 }
1566
1567 try
1568 {
1569 /* Tracking code */
1570
1571 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
1572 {
1573 for (RTNOC = 0; RTNOC < Decimal_KeyArray4.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1574 {
1575 Decimal_Keys[RTNOC] = Decimal_KeyArray4[RTNOC % KeyLength4];
1576 }
1577
1578 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1579 {
1580 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1581 }
1582
1583 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop subtraction) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递减运算.
1584 {
1585 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
1586 }
1587
1588 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1589 {
1590 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1591 }
1592
1593 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop multiplication) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递乘运算.
1594 {
1595 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
1596 }
1597
1598 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1599 {
1600 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1601 }
1602
1603 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop addition) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递增运算.
1604 {
1605 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
1606 }
1607
1608 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (XOR = Exclusive or) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal
1609 {
1610 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1611 }
1612
1613 for (RTNOC = 0; RTNOC < Decimal_FileBufferArray.max_size(); RTNOC++) //Execute the (loop division) operation of byte-by-byte and Decimal_KeyArray on the data in the bufferOriginal. 对buffer中的数据逐字节的和E_KEY进行递除运算.
1614 {
1615 if (Decimal_KeyArray4[RTNOC] == 0)
1616 {
1617 RTNOC += 1;
1618 }
1619 else if (Decimal_KeyArray4[RTNOC] != 0)
1620 {
1621 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray4[RTNOC] == 0)
1622 {
1623 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
1624 }
1625 }
1626 }
1627
1628 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
1629 {
1630 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
1631 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
1632 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
1633
1634 myBuffer_byteArray[1024] = {0x00};
1635 myBuffer_byteArray2[1024] = {0x00};
1636 }
1637 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
1638 }
1639 }
1640 catch (const exception &except_massage)
1641 {
1642 std::cout << except_massage.what() << std::endl;
1643 }
1644 }
1645 fseek(FilePointerSource, 0L, SEEK_SET);
1646 fseek(FilePointerTarget, 0L, SEEK_SET);
1647 }
1648
1649 system("@color 07");
1650
1651 if (NOIDM < MAX_NOT_D_MODULE || NOIDM == 12800)
1652 {
1653 cout << "The display of the interaction progress has been closed for the decryption function." << endl;
1654 cout << "已经关闭解密功能的交互进度的显示。" << endl;
1655 break; //End decrypting process
1656 }
1657 else
1658 {
1659 NOIDM = 0;
1660 fclose(FilePointerSource);
1661 fclose(FilePointerTarget);
1662 return FAILED;
1663 }
1664 }
1665
1666 /***********************************************************************************************************************************************************/
1667
1668 /*解密算法结束*/
1669
1670 fclose(FilePointerSource);
1671 fclose(FilePointerTarget);
1672
1673 //DeleteFile(D_SourceFileCharPath); /*This is windows API function*/
1674 //remove(D_SourceFileCharPath); /*This is C & C++ language the delete file common IO function, use in the linux and unix or windows platform.*/
1675
1676 return SUCCESSFUL;
1677}