Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include <iostream>
  2. #include<experimental/filesystem>
  3. #include<filesystem>
  4. #include<fstream>
  5. #include<string>
  6. #include<cstdlib>
  7. #include<ctime>
  8. #include<cstring>
  9.  
  10. using namespace std;
  11. using namespace experimental::filesystem;
  12.  
  13. hash<string>b;
  14. string s;
  15. unsigned long long z = 0;
  16. ofstream f;
  17. ifstream f1;
  18.  
  19. unsigned short CRC16(unsigned short len, string s)
  20. {
  21. unsigned short crc = 65535;
  22. unsigned char *str = new unsigned char[s.size()];
  23. for (size_t i = 0; i < s.size(); i++)
  24. {
  25. str[i] = s[i];
  26. }
  27. while (len)
  28. {
  29. crc ^= *str << 8;
  30. *str++;
  31. for (unsigned char i = 0; i < 8; i++)
  32. {
  33. if (crc & 32768)
  34. {
  35. crc = (crc << 1) ^ 4129;
  36. }
  37. else crc = crc << 1;
  38. }
  39. len--;
  40. }
  41. cout << crc << endl;
  42. return crc;
  43. }
  44.  
  45. void hash_sum(string &p)
  46. {
  47. f.open(p);
  48. for (auto i : directory_iterator("C:\\Test"))
  49. {
  50. path a = i;
  51. f1.open(i);
  52. while (!f1.eof())
  53. {
  54. getline(f1, s);
  55. z += CRC16(s.size(),s);
  56. }
  57. f << z << " " << a.stem() << " " << file_size(a) << " " << a << endl;
  58. z = 0;
  59. f1.close();
  60. }
  61. f.close();
  62. }
  63.  
  64. vector<string> init()
  65. {
  66. string q, w;
  67. vector<string> res;
  68. while (!f1.eof())
  69. {
  70. getline(f1, q);
  71. if (q == "")break;
  72. for (size_t i = 0; q[i] != ' '; i++)
  73. {
  74. w += q[i];
  75. }
  76. res.push_back(w);
  77. }
  78. return res;
  79. }
  80.  
  81. int main()
  82. {
  83. srand(time(NULL));
  84. string p = "C:\\1\\List.txt";
  85. hash_sum(p);
  86.  
  87. for (auto i : directory_iterator("C:\\Test"))
  88. {
  89. if (rand() % 2)
  90. {
  91. vector<string>s1;
  92. f1.open(i);
  93. while (!f1.eof())
  94. {
  95. getline(f1, s);
  96. s1.push_back(s);
  97. }
  98. f1.close();
  99. for (size_t i = 0; i < s1.size(); i++)
  100. {
  101. for (size_t j = 0; j < s1[i].size(); j++)
  102. {
  103. if (rand() % 2)
  104. {
  105. s1[i][j] = (char)rand() % 128;
  106. }
  107. }
  108. }
  109. f.open(i);
  110. for (size_t i = 0; i < s1.size(); i++)
  111. {
  112. f << s1[i];
  113. if (i + 1 != s1.size())f << endl;
  114. }
  115. f.close();
  116. }
  117. }
  118. p = "C:\\1\\List1.txt";
  119. hash_sum(p);
  120. f1.open("C:\\1\\List.txt");
  121. vector<string>fir = init();
  122. f1.close();
  123. f1.open(p);
  124. vector<string>sec = init();
  125. f1.close();
  126. for (size_t i = 0; i < fir.size(); i++)
  127. {
  128. if (fir[i] == sec[i])cout << "Correct" << endl;
  129. else cout << "Incorrect" << endl;
  130. }
  131.  
  132. return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement