· 5 years ago · Dec 03, 2020, 05:22 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;
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;
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 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
660 {
661 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of encryption key 3 ." << endl;
662 Decimal_KeyArray3[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
663 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
664 }
665 string fileKey_decimalString, keyHexadecimal_string;
666 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
667 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray3[RTNOC]));
668 cout << "Current hexdecimal temporary key is :\n"
669 << keyHexadecimal_string << endl;
670 cout << "Current decimal file key is :\n"
671 << fileKey_decimalString << endl;
672 dataString.clear();
673 keyHexadecimal_string.clear();
674 fileKey_decimalString.clear();
675 cout << "Current encipher integer key three is : " << Decimal_KeyArray3[RTNOC] << endl;
676
677 try
678 {
679 /* Tracking code */
680
681 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
682 {
683 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
684 {
685 Decimal_Keys[RTNOC] = Decimal_KeyArray3[RTNOC % KeyLength3];
686 }
687
688 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
689 {
690 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray3[RTNOC];
691 }
692
693 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进行递减运算.
694 {
695 Decimal_FileBufferArray[RTNOC] -= Decimal_KeyArray3[RTNOC];
696 }
697
698 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
699 {
700 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray3[RTNOC];
701 }
702
703 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进行递除运算.
704 {
705 if (Decimal_KeyArray3[RTNOC] == 0)
706 {
707 RTNOC += 1;
708 }
709 else if (Decimal_KeyArray3[RTNOC] != 0)
710 {
711 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray3[RTNOC] == 0)
712 {
713 Decimal_FileBufferArray[RTNOC] /= Decimal_KeyArray3[RTNOC];
714 }
715 }
716 }
717
718 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
719 {
720 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray3[RTNOC];
721 }
722
723 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进行递增运算.
724 {
725 Decimal_FileBufferArray[RTNOC] += Decimal_KeyArray3[RTNOC];
726 }
727
728 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
729 {
730 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray3[RTNOC];
731 }
732
733 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进行递乘运算.
734 {
735 Decimal_FileBufferArray[RTNOC] *= Decimal_KeyArray3[RTNOC];
736 }
737
738 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
739 {
740 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
741 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
742 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
743
744 myBuffer_byteArray[1024] = {0x00};
745 myBuffer_byteArray2[1024] = {0x00};
746 }
747 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
748 }
749 }
750 catch (const exception &except_massage)
751 {
752 std::cout << except_massage.what() << std::endl;
753 }
754 }
755 fseek(FilePointerSource, 0L, SEEK_SET);
756 fseek(FilePointerTarget, 0L, SEEK_SET);
757 }
758
759 //文件和密钥4在缓冲区中计算
760 //The file and key4 are counted in Buffer
761
762 cout << "Encrypting...... Currently in use the fourth key" << endl;
763
764 //Mini-Group Encryption Module Key4-Calculate1
765
766 for (NOIEM = 0; NOIEM < MINI_NOT_E_GROUP; NOIEM++)
767 {
768 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,直到文件结束。
769 {
770 FileAccessPointer_Source = ftell(FilePointerSource);
771 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
772
773 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength4, FilePointerSource);
774
775 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
776 {
777 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
778 }
779 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
780 {
781 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(E_KEY4[RTNOC]);
782 }
783
784 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
785 //signedChar_convertionToUnsignedChar<char,my_byte>(E_KEY4, myBuffer_byteArray2)
786
787 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
788 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(E_KEY4);
789
790 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
791 {
792 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the encryption." << endl;
793 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
794 }
795 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
796 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
797 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
798 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
799 cout << "Current hexdecimal temporary bufferOriginal is :\n"
800 << byteHexadecimal_string << endl;
801 cout << "Current decimal file bufferOriginal is :\n"
802 << fileBuffer_decimalString << std::dec << endl;
803 dataString.clear();
804 byteHexadecimal_string.clear();
805 fileBuffer_decimalString.clear();
806 }
807
808 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
809 {
810 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of encryption key 4 ." << endl;
811 Decimal_KeyArray4[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
812 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
813 }
814 string fileKey_decimalString, keyHexadecimal_string;
815 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
816 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray4[RTNOC]));
817 cout << "Current hexdecimal temporary key is :\n"
818 << keyHexadecimal_string << endl;
819 cout << "Current decimal file key is :\n"
820 << fileKey_decimalString << endl;
821 dataString.clear();
822 keyHexadecimal_string.clear();
823 fileKey_decimalString.clear();
824 cout << "Current encipher integer key four is : " << Decimal_KeyArray4[RTNOC] << endl;
825
826 try
827 {
828 /* Tracking code */
829
830 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
831 {
832 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
833 {
834 Decimal_Keys[RTNOC] = Decimal_KeyArray4[RTNOC % KeyLength4];
835 }
836
837 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
838 {
839 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray4[RTNOC];
840 }
841
842 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进行递增运算.
843 {
844 Decimal_FileBufferArray[RTNOC] += Decimal_KeyArray4[RTNOC];
845 }
846
847 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
848 {
849 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray4[RTNOC];
850 }
851
852 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进行递乘运算.
853 {
854 Decimal_FileBufferArray[RTNOC] *= Decimal_KeyArray4[RTNOC];
855 }
856
857 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
858 {
859 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray4[RTNOC];
860 }
861
862 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进行递减运算.
863 {
864 Decimal_FileBufferArray[RTNOC] -= Decimal_KeyArray4[RTNOC];
865 }
866
867 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
868 {
869 Decimal_FileBufferArray[RTNOC] ^= Decimal_KeyArray4[RTNOC];
870 }
871
872 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进行递除运算.
873 {
874 if (Decimal_KeyArray4[RTNOC] == 0)
875 {
876 RTNOC += 1;
877 }
878 if (Decimal_KeyArray4[RTNOC] != 0)
879 {
880 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray4[RTNOC] == 0)
881 {
882 Decimal_FileBufferArray[RTNOC] /= Decimal_KeyArray4[RTNOC];
883 }
884 }
885 }
886
887 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
888 {
889 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
890 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
891 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
892
893 myBuffer_byteArray[1024] = {0x00};
894 myBuffer_byteArray2[1024] = {0x00};
895 }
896 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
897 }
898 }
899 catch (const exception &except_massage)
900 {
901 std::cout << except_massage.what() << std::endl;
902 }
903 }
904 fseek(FilePointerSource, 0L, SEEK_SET);
905 fseek(FilePointerTarget, 0L, SEEK_SET);
906 }
907
908 system("@color 07");
909
910 if (NOIEM < MAX_NOT_E_MODULE || NOIEM == 12800)
911 {
912 cout << "The display of the interaction progress has been closed for the encryption function." << endl;
913 cout << "已经关闭加密功能的交互进度的显示。" << endl;
914 break; //End encrypting process
915 }
916 else
917 {
918 NOIEM = 0;
919 fclose(FilePointerSource);
920 fclose(FilePointerTarget);
921 return FAILED;
922 }
923 }
924
925 /***********************************************************************************************************************************************************/
926
927 /*加密算法结束*/
928
929 fclose(FilePointerSource);
930 fclose(FilePointerTarget);
931
932 //DeleteFile(E_SourceFileCharPath); /*This is windows API function*/
933 //remove(E_SourceFileCharPath); /*This is C & C++ language the delete file common IO function, use in the linux and unix or windows platform.*/
934
935 return SUCCESSFUL;
936}
937
938/*******************************************
939* 解密文件
940*
941* D_SourceFileName 需要解密的文件名
942* D_KEY 密钥
943* D_TargetFileNewName 解密完成后要保存的文件名
944*
945* @return 解密成功或失败的数字表示
946*
947* 0 = 解密失败
948* 1 = 解密成功
949********************************************/
950
951int RunDecryptFile(const char *D_SourceFileCharPath, char *D_KEY, char *D_KEY2, char *D_KEY3, char *D_KEY4, const char *D_TargetFileCharPath)
952{
953 cin.tie(0);
954 cout.tie(0);
955
956 FILE *FilePointerSource, *FilePointerTarget; //需要打开的文件的指针 Need to open the file MyCharPointer
957 char bufferOriginal[1024] = {'\x00'}; //文件流缓冲区,用于存放从文件读取的数据 File stream bufferOriginal, used to store the data read from the file
958
959 size_t FileReadByte_DataSize, //每次从文件中读取的字节数 The number of bytes read from the file each time
960 RTNOC, //运行循环次数 (Run The Number Of Cycles)
961 KeyLength = getArraySize(D_KEY), //密钥的长度 The length of the key
962 KeyLength2 = getArraySize(D_KEY2),
963 KeyLength3 = getArraySize(D_KEY3),
964 KeyLength4 = getArraySize(D_KEY4);
965
966 FilePointerSource = fopen(D_SourceFileCharPath, "rb"); //以二进制方式读取文件
967 if (FilePointerSource == NULL)
968 {
969 //printf("File[%s]failed to open, please check whether the file path and name are entered correctly !\n", D_SourceFileCharPath);
970 //printf("文件[%s]打开失败,请检查文件路径和名称是否输入正确 !\n", D_SourceFileCharPath);
971 cout << "File "
972 << "[ " << D_SourceFileCharPath << " ]"
973 << " failed to open, please check whether the file path and name are entered correctly !" << endl;
974 cout << "文件 "
975 << "[ " << D_SourceFileCharPath << " ]"
976 << " 打开失败,请检查文件路径和名称是否输入正确 !" << endl;
977 getchar();
978 return RUNTIME_ERROR;
979 }
980
981 FilePointerTarget = fopen(D_TargetFileCharPath, "wb+"); //以二进制方式写入文件
982 if (FilePointerTarget == NULL)
983 {
984 //printf("File[%s]creation/write failed! Please check whether the file path and name are entered correctly !\n", D_TargetFileCharPath);
985 //printf("文件[%s]创建/写入失败!请检查文件路径和名称是否输入正确 !\n", D_TargetFileCharPath);
986 cout << "File "
987 << "[ " << D_TargetFileCharPath << " ]"
988 << " creation/write failed! Please check whether the file path and name are entered correctly !" << endl;
989 cout << "文件 "
990 << "[ " << D_TargetFileCharPath << " ]"
991 << " 创建/写入失败!请检查文件路径和名称是否输入正确 !" << endl;
992 getchar();
993 return RUNTIME_ERROR;
994 }
995
996 /*解密算法开始*/
997
998 /***********************************************************************************************************************************************************/
999
1000 //运行大型解密模块
1001 //Run large decryption module
1002
1003 //文件和密钥在缓冲区中计算
1004 //The file and key are counted in Buffer
1005
1006 /*Skip file header (128 byte)*/
1007 fseek(FilePointerSource, 128L, SEEK_SET); //Move the file MyCharPointer to the 128th byte of the file start
1008 FileHeaderSignatures = ftell(FilePointerSource); //Get this file header length
1009 fseek(FilePointerSource, 0L, SEEK_SET); //Move the file MyCharPointer to this file start point
1010
1011 /*Continuously read fileheadersignatures length data from file, save to bufferOriginal until end of file*/
1012 while ((FileHeaderByteData = fread(bufferOriginal, 1, FileHeaderSignatures, FilePointerSource)) > 0)
1013 {
1014 fwrite(bufferOriginal, 1, FileHeaderByteData, FilePointerTarget); //Write data from bufferOriginal to file
1015 }
1016
1017 /*The MyCharPointer to the file stream is moved, and the read and write data continues to start at the 128rd byte*/
1018 fseek(FilePointerSource, 129L, SEEK_SET);
1019 fseek(FilePointerTarget, 129L, SEEK_SET);
1020
1021 static array<my_uint, 1024> Decimal_FileBufferArray;
1022 Decimal_FileBufferArray.fill(0);
1023 static array<my_byte, 1024> ByteArray_FileBuffer;
1024 ByteArray_FileBuffer.fill('\xff');
1025
1026 static array<my_uint, 1024> Decimal_Keys; //paswords for decryption processing
1027
1028 static array<my_uint, 1024> Decimal_KeyArray;
1029 static array<my_uint, 1024> Decimal_KeyArray2;
1030 static array<my_uint, 1024> Decimal_KeyArray3;
1031 static array<my_uint, 1024> Decimal_KeyArray4;
1032
1033 my_byte myBuffer_byteArray[1024] = {0xff}; //converted type data of file buffer
1034 my_byte myBuffer_byteArray2[1024] = {0xff};
1035
1036 //my_byte* myBuffer_byteArray = nullptr;
1037 //my_byte* myBuffer_byteArray2 = nullptr;
1038
1039 for (NOIDM = 0; NOIDM < MAX_NOT_D_MODULE; NOIDM++)
1040 {
1041 system("cls");
1042 double currentWorkMainProgress = NOIDM / (((MAX_NOT_D_MODULE - 1) / 100) * 1);
1043 cout << "Decrypting Progress = " << currentWorkMainProgress << "%" << endl;
1044 system("@color 6F");
1045 std::cout << "Please wait, read and write in the file......" << endl;
1046 std::cout << "请等待,文件读写中......" << endl;
1047 system("@color 0D");
1048 cout << "The display of the interaction progress has been opened using the request for the decryption function." << endl;
1049 cout << "使用解密功能的请求,交互进度的显示已经被打开。" << endl;
1050 cout << "Decrypting...... Currently in use the first key" << endl;
1051
1052 my_l_sint FileAccessPointer_Source = ftell(FilePointerSource);
1053 size_t FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1054
1055 //Mini-Group Decryption Module Key1-Calculate1
1056 for (NOIDM = 0; NOIDM < MINI_NOT_D_GROUP; NOIDM++)
1057 {
1058 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,直到文件结束。
1059 {
1060 FileAccessPointer_Source = ftell(FilePointerSource);
1061 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1062
1063 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength, FilePointerSource);
1064
1065 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1066 {
1067 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
1068 }
1069 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1070 {
1071 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(D_KEY[RTNOC]);
1072 }
1073
1074 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
1075 //signedChar_convertionToUnsignedChar<char,my_byte>(D_KEY, myBuffer_byteArray2);
1076
1077 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
1078 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(D_KEY);
1079
1080 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
1081 {
1082 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the decryption." << endl;
1083 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
1084 }
1085 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
1086 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
1087 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1088 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
1089 cout << "Current hexdecimal temporary bufferOriginal is :\n"
1090 << byteHexadecimal_string << endl;
1091 cout << "Current decimal file bufferOriginal is :\n"
1092 << fileBuffer_decimalString << std::dec << endl;
1093 dataString.clear();
1094 byteHexadecimal_string.clear();
1095 fileBuffer_decimalString.clear();
1096
1097 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
1098 {
1099 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of decryption key 1 ." << endl;
1100 Decimal_KeyArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
1101 }
1102 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
1103 string fileKey_decimalString, keyHexadecimal_string;
1104 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1105 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray[RTNOC]));
1106 cout << "Current hexdecimal temporary key is :\n"
1107 << keyHexadecimal_string << endl;
1108 cout << "Current decimal file key is :\n"
1109 << fileKey_decimalString << endl;
1110 dataString.clear();
1111 keyHexadecimal_string.clear();
1112 fileKey_decimalString.clear();
1113 cout << "Current decipher integer key one is : " << Decimal_KeyArray[RTNOC] << endl;
1114
1115 try
1116 {
1117 /* Tracking code */
1118
1119 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
1120 {
1121 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
1122 {
1123 Decimal_Keys[RTNOC] = Decimal_KeyArray[RTNOC % KeyLength];
1124 }
1125
1126 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
1127 {
1128 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1129 }
1130
1131 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进行递除运算.
1132 {
1133 if (Decimal_KeyArray[RTNOC] == 0)
1134 {
1135 RTNOC += 1;
1136 }
1137 else if (Decimal_KeyArray[RTNOC] != 0)
1138 {
1139 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray[RTNOC] == 0)
1140 {
1141 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
1142 }
1143 }
1144 }
1145
1146 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
1147 {
1148 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1149 }
1150
1151 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进行递减运算.
1152 {
1153 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
1154 }
1155
1156 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
1157 {
1158 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1159 }
1160
1161 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进行递乘运算.
1162 {
1163 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
1164 }
1165
1166 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
1167 {
1168 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1169 }
1170
1171 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进行递增运算.
1172 {
1173 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
1174 }
1175
1176 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
1177 {
1178 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
1179 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
1180 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
1181
1182 myBuffer_byteArray[1024] = {0x00};
1183 myBuffer_byteArray2[1024] = {0x00};
1184 }
1185 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
1186 }
1187 }
1188 catch (const exception &except_massage)
1189 {
1190 std::cout << except_massage.what() << std::endl;
1191 }
1192 }
1193 fseek(FilePointerSource, 0L, SEEK_SET);
1194 fseek(FilePointerTarget, 0L, SEEK_SET);
1195 }
1196
1197 //文件和密钥2在缓冲区中计算
1198 //The file and key2 are counted in Buffer
1199
1200 cout << "Decrypting...... Currently in use the second key" << endl;
1201
1202 //Mini-Group Decryption Module Key2-Calculate1
1203 for (NOIDM = 0; NOIDM < MINI_NOT_D_GROUP; NOIDM++)
1204 {
1205 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //不断地从文件中读取 KeyLength2 长度的数据,保存到buffer,直到文件结束
1206 {
1207 FileAccessPointer_Source = ftell(FilePointerSource);
1208 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1209
1210 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength2, FilePointerSource);
1211
1212 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1213 {
1214 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
1215 }
1216 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1217 {
1218 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(D_KEY2[RTNOC]);
1219 }
1220
1221 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
1222 //signedChar_convertionToUnsignedChar<char,my_byte>(D_KEY2, myBuffer_byteArray2);
1223
1224 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
1225 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(D_KEY2);
1226
1227 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
1228 {
1229 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the decryption." << endl;
1230 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
1231 }
1232 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
1233 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
1234 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1235 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
1236 cout << "Current hexdecimal temporary bufferOriginal is :\n"
1237 << byteHexadecimal_string << endl;
1238 cout << "Current decimal file bufferOriginal is :\n"
1239 << fileBuffer_decimalString << std::dec << endl;
1240 dataString.clear();
1241 byteHexadecimal_string.clear();
1242 fileBuffer_decimalString.clear();
1243
1244 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
1245 {
1246 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of decryption key 2 ." << endl;
1247 Decimal_KeyArray2[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
1248 }
1249 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
1250 string fileKey_decimalString, keyHexadecimal_string;
1251 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1252 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray2[RTNOC]));
1253 cout << "Current hexdecimal temporary key is :\n"
1254 << keyHexadecimal_string << endl;
1255 cout << "Current decimal file key is :\n"
1256 << fileKey_decimalString << endl;
1257 dataString.clear();
1258 keyHexadecimal_string.clear();
1259 fileKey_decimalString.clear();
1260 cout << "Current decipher integer key two is : " << Decimal_KeyArray2[RTNOC] << endl;
1261
1262 try
1263 {
1264 /* Tracking code */
1265
1266 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
1267 {
1268 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
1269 {
1270 Decimal_Keys[RTNOC] = Decimal_KeyArray2[RTNOC % KeyLength2];
1271 }
1272
1273 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
1274 {
1275 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1276 }
1277
1278 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进行递乘运算.
1279 {
1280 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
1281 }
1282
1283 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
1284 {
1285 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1286 }
1287
1288 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进行递增运算.
1289 {
1290 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
1291 }
1292
1293 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
1294 {
1295 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1296 }
1297
1298 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进行递除运算.
1299 {
1300 if (Decimal_KeyArray2[RTNOC] == 0)
1301 {
1302 RTNOC += 1;
1303 }
1304 else if (Decimal_KeyArray2[RTNOC] != 0)
1305 {
1306 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray2[RTNOC] == 0)
1307 {
1308 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
1309 }
1310 }
1311 }
1312
1313 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
1314 {
1315 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1316 }
1317
1318 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进行递减运算.
1319 {
1320 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
1321 }
1322
1323 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
1324 {
1325 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
1326 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
1327 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
1328
1329 myBuffer_byteArray[1024] = {0x00};
1330 myBuffer_byteArray2[1024] = {0x00};
1331 }
1332 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
1333 }
1334 }
1335 catch (const exception &except_massage)
1336 {
1337 std::cout << except_massage.what() << std::endl;
1338 }
1339 }
1340 fseek(FilePointerSource, 0L, SEEK_SET);
1341 fseek(FilePointerTarget, 0L, SEEK_SET);
1342 }
1343
1344 //文件和密钥3在缓冲区中计算
1345 //The file and key3 are counted in Buffer
1346
1347 cout << "Decrypting...... Currently in use the third key" << endl;
1348
1349 //Mini-Group Decryption Module Key3-Calculate1
1350 for (NOIDM = 0; NOIDM < MINI_NOT_D_GROUP; NOIDM++)
1351 {
1352 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //不断地从文件中读取 KeyLength3 长度的数据,保存到buffer,直到文件结束
1353 {
1354 FileAccessPointer_Source = ftell(FilePointerSource);
1355 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1356
1357 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength3, FilePointerSource);
1358
1359 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1360 {
1361 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
1362 }
1363 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1364 {
1365 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(D_KEY3[RTNOC]);
1366 }
1367
1368 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
1369 //signedChar_convertionToUnsignedChar<char,my_byte>(D_KEY3, myBuffer_byteArray2);
1370
1371 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
1372 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(D_KEY3);
1373
1374 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
1375 {
1376 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the decryption." << endl;
1377 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
1378 }
1379 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
1380 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
1381 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1382 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
1383 cout << "Current hexdecimal temporary bufferOriginal is :\n"
1384 << byteHexadecimal_string << endl;
1385 cout << "Current decimal file bufferOriginal is :\n"
1386 << fileBuffer_decimalString << std::dec << endl;
1387 dataString.clear();
1388 byteHexadecimal_string.clear();
1389 fileBuffer_decimalString.clear();
1390
1391 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
1392 {
1393 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of decryption key 3 ." << endl;
1394 Decimal_KeyArray3[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
1395 }
1396 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
1397 string fileKey_decimalString, keyHexadecimal_string;
1398 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1399 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray3[RTNOC]));
1400 cout << "Current hexdecimal temporary key is :\n"
1401 << keyHexadecimal_string << endl;
1402 cout << "Current decimal file key is :\n"
1403 << fileKey_decimalString << endl;
1404 dataString.clear();
1405 keyHexadecimal_string.clear();
1406 fileKey_decimalString.clear();
1407 cout << "Current decipher integer key three is : " << Decimal_KeyArray3[RTNOC] << endl;
1408
1409 try
1410 {
1411 /* Tracking code */
1412
1413 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
1414 {
1415 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
1416 {
1417 Decimal_Keys[RTNOC] = Decimal_KeyArray3[RTNOC % KeyLength3];
1418 }
1419
1420 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
1421 {
1422 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1423 }
1424
1425 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进行递增运算.
1426 {
1427 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
1428 }
1429
1430 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
1431 {
1432 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1433 }
1434
1435 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进行递除运算.
1436 {
1437 if (Decimal_KeyArray3[RTNOC] == 0)
1438 {
1439 RTNOC += 1;
1440 }
1441 else if (Decimal_KeyArray3[RTNOC] != 0)
1442 {
1443 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray3[RTNOC] == 0)
1444 {
1445 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
1446 }
1447 }
1448 }
1449
1450 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
1451 {
1452 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1453 }
1454
1455 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进行递减运算.
1456 {
1457 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
1458 }
1459
1460 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
1461 {
1462 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1463 }
1464
1465 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进行递乘运算.
1466 {
1467 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
1468 }
1469
1470 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
1471 {
1472 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
1473 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
1474 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
1475
1476 myBuffer_byteArray[1024] = {0x00};
1477 myBuffer_byteArray2[1024] = {0x00};
1478 }
1479 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
1480 }
1481 }
1482 catch (const exception &except_massage)
1483 {
1484 std::cout << except_massage.what() << std::endl;
1485 }
1486 }
1487 fseek(FilePointerSource, 0L, SEEK_SET);
1488 fseek(FilePointerTarget, 0L, SEEK_SET);
1489 }
1490
1491 //文件和密钥4在缓冲区中计算
1492 //The file and key4 are counted in Buffer
1493
1494 cout << "Decrypting...... Currently in use the fourth key" << endl;
1495
1496 //Mini-Group Decryption Module Key4-Calculate1
1497 for (NOIDM = 0; NOIDM < MINI_NOT_D_GROUP; NOIDM++)
1498 {
1499 while (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile) //不断地从文件中读取 KeyLength4 长度的数据,保存到buffer,直到文件结束
1500 {
1501 FileAccessPointer_Source = ftell(FilePointerSource);
1502 FileAccessPointer_SourceEndOfFile = seek_cIO_fileEOF(FilePointerSource);
1503
1504 FileReadByte_DataSize = fread(bufferOriginal, 1, KeyLength4, FilePointerSource);
1505
1506 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1507 {
1508 myBuffer_byteArray[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(bufferOriginal[RTNOC]);
1509 }
1510 for (RTNOC = 0; RTNOC < getArraySizeNew(bufferOriginal); RTNOC++)
1511 {
1512 myBuffer_byteArray2[RTNOC] = AnyToAny_ConvertFromBoost<my_sbyte, my_byte>(D_KEY4[RTNOC]);
1513 }
1514
1515 //signedChar_convertionToUnsignedChar<char,my_byte>(bufferOriginal, myBuffer_byteArray);
1516 //signedChar_convertionToUnsignedChar<char,my_byte>(D_KEY4, myBuffer_byteArray2);
1517
1518 //myBuffer_byteArray = AnyToAny_ConvertFromBoost<char *, my_byte *>(bufferOriginal);
1519 //myBuffer_byteArray2 = AnyToAny_ConvertFromBoost<char *,my_byte *>(D_KEY4);
1520
1521 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray); RTNOC++)
1522 {
1523 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of source file bufferOriginal to the decryption." << endl;
1524 Decimal_FileBufferArray[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray[RTNOC]);
1525 }
1526 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray;
1527 string fileBuffer_decimalString, byteHexadecimal_string, dataString;
1528 byteHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1529 fileBuffer_decimalString = dataString.append(to_string(Decimal_FileBufferArray[RTNOC]));
1530 cout << "Current hexdecimal temporary bufferOriginal is :\n"
1531 << byteHexadecimal_string << endl;
1532 cout << "Current decimal file bufferOriginal is :\n"
1533 << fileBuffer_decimalString << std::dec << endl;
1534 dataString.clear();
1535 byteHexadecimal_string.clear();
1536 fileBuffer_decimalString.clear();
1537
1538 for (RTNOC = 0; RTNOC < getArraySize<my_byte[1024]>(myBuffer_byteArray2); RTNOC++)
1539 {
1540 cout << "Calling the MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger() function of decryption key 4 ." << endl;
1541 Decimal_KeyArray4[RTNOC] = MY_EODF_CA_UTIL::MyTable_hexadecimalToInteger(myBuffer_byteArray2[RTNOC]);
1542 }
1543 unsigned char *MyUnsignedCharPointer = myBuffer_byteArray2;
1544 string fileKey_decimalString, keyHexadecimal_string;
1545 keyHexadecimal_string = getRAW_String(dataString.append(reinterpret_cast<const char *>(MyUnsignedCharPointer)));
1546 fileKey_decimalString = dataString.append(to_string(Decimal_KeyArray4[RTNOC]));
1547 cout << "Current hexdecimal temporary key is :\n"
1548 << keyHexadecimal_string << endl;
1549 cout << "Current decimal file key is :\n"
1550 << fileKey_decimalString << endl;
1551 dataString.clear();
1552 keyHexadecimal_string.clear();
1553 fileKey_decimalString.clear();
1554 cout << "Current decipher integer key four is : " << Decimal_KeyArray[RTNOC] << endl;
1555
1556 try
1557 {
1558 /* Tracking code */
1559
1560 if (FileAccessPointer_Source != FileAccessPointer_SourceEndOfFile)
1561 {
1562 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
1563 {
1564 Decimal_Keys[RTNOC] = Decimal_KeyArray4[RTNOC % KeyLength4];
1565 }
1566
1567 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
1568 {
1569 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1570 }
1571
1572 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进行递减运算.
1573 {
1574 Decimal_FileBufferArray[RTNOC] -= Decimal_Keys[RTNOC];
1575 }
1576
1577 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
1578 {
1579 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1580 }
1581
1582 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进行递乘运算.
1583 {
1584 Decimal_FileBufferArray[RTNOC] *= Decimal_Keys[RTNOC];
1585 }
1586
1587 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
1588 {
1589 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1590 }
1591
1592 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进行递增运算.
1593 {
1594 Decimal_FileBufferArray[RTNOC] += Decimal_Keys[RTNOC];
1595 }
1596
1597 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
1598 {
1599 Decimal_FileBufferArray[RTNOC] ^= Decimal_Keys[RTNOC];
1600 }
1601
1602 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进行递除运算.
1603 {
1604 if (Decimal_KeyArray4[RTNOC] == 0)
1605 {
1606 RTNOC += 1;
1607 }
1608 else if (Decimal_KeyArray4[RTNOC] != 0)
1609 {
1610 if (Decimal_FileBufferArray[RTNOC] % Decimal_KeyArray4[RTNOC] == 0)
1611 {
1612 Decimal_FileBufferArray[RTNOC] /= Decimal_Keys[RTNOC];
1613 }
1614 }
1615 }
1616
1617 for (RTNOC = 0; RTNOC <= Decimal_FileBufferArray.max_size(); RTNOC++)
1618 {
1619 cout << "Calling the MY_EODF_CA_UTIL::MyTable_integerToHexadecimal() function of decimal array bufferOriginal to the converting......" << endl;
1620 ByteArray_FileBuffer[RTNOC] = MY_EODF_CA_UTIL::MyTable_integerToHexadecimal(Decimal_FileBufferArray[RTNOC]);
1621 bufferOriginal[RTNOC] = AnyToAny_ConvertFromBoost<my_byte, my_sbyte>(ByteArray_FileBuffer[RTNOC]);
1622
1623 myBuffer_byteArray[1024] = {0x00};
1624 myBuffer_byteArray2[1024] = {0x00};
1625 }
1626 fwrite(bufferOriginal, 1, FileReadByte_DataSize, FilePointerTarget); //Write bufferOriginal data to file. 将buffer中的数据写入文件。
1627 }
1628 }
1629 catch (const exception &except_massage)
1630 {
1631 std::cout << except_massage.what() << std::endl;
1632 }
1633 }
1634 fseek(FilePointerSource, 0L, SEEK_SET);
1635 fseek(FilePointerTarget, 0L, SEEK_SET);
1636 }
1637
1638 system("@color 07");
1639
1640 if (NOIDM < MAX_NOT_D_MODULE || NOIDM == 12800)
1641 {
1642 cout << "The display of the interaction progress has been closed for the decryption function." << endl;
1643 cout << "已经关闭解密功能的交互进度的显示。" << endl;
1644 break; //End decrypting process
1645 }
1646 else
1647 {
1648 NOIDM = 0;
1649 fclose(FilePointerSource);
1650 fclose(FilePointerTarget);
1651 return FAILED;
1652 }
1653 }
1654
1655 /***********************************************************************************************************************************************************/
1656
1657 /*解密算法结束*/
1658
1659 fclose(FilePointerSource);
1660 fclose(FilePointerTarget);
1661
1662 //DeleteFile(D_SourceFileCharPath); /*This is windows API function*/
1663 //remove(D_SourceFileCharPath); /*This is C & C++ language the delete file common IO function, use in the linux and unix or windows platform.*/
1664
1665 return SUCCESSFUL;
1666}