Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<experimental/filesystem>
- #include<filesystem>
- #include<fstream>
- #include<string>
- #include<cstdlib>
- #include<ctime>
- #include<cstring>
- using namespace std;
- using namespace experimental::filesystem;
- hash<string>b;
- string s;
- unsigned long long z = 0;
- ofstream f;
- ifstream f1;
- unsigned short CRC16(unsigned short len, string s)
- {
- unsigned short crc = 65535;
- unsigned char *str = new unsigned char[s.size()];
- for (size_t i = 0; i < s.size(); i++)
- {
- str[i] = s[i];
- }
- while (len)
- {
- crc ^= *str << 8;
- *str++;
- for (unsigned char i = 0; i < 8; i++)
- {
- if (crc & 32768)
- {
- crc = (crc << 1) ^ 4129;
- }
- else crc = crc << 1;
- }
- len--;
- }
- cout << crc << endl;
- return crc;
- }
- void hash_sum(string &p)
- {
- f.open(p);
- for (auto i : directory_iterator("C:\\Test"))
- {
- path a = i;
- f1.open(i);
- while (!f1.eof())
- {
- getline(f1, s);
- z += CRC16(s.size(),s);
- }
- f << z << " " << a.stem() << " " << file_size(a) << " " << a << endl;
- z = 0;
- f1.close();
- }
- f.close();
- }
- vector<string> init()
- {
- string q, w;
- vector<string> res;
- while (!f1.eof())
- {
- getline(f1, q);
- if (q == "")break;
- for (size_t i = 0; q[i] != ' '; i++)
- {
- w += q[i];
- }
- res.push_back(w);
- }
- return res;
- }
- int main()
- {
- srand(time(NULL));
- string p = "C:\\1\\List.txt";
- hash_sum(p);
- for (auto i : directory_iterator("C:\\Test"))
- {
- if (rand() % 2)
- {
- vector<string>s1;
- f1.open(i);
- while (!f1.eof())
- {
- getline(f1, s);
- s1.push_back(s);
- }
- f1.close();
- for (size_t i = 0; i < s1.size(); i++)
- {
- for (size_t j = 0; j < s1[i].size(); j++)
- {
- if (rand() % 2)
- {
- s1[i][j] = (char)rand() % 128;
- }
- }
- }
- f.open(i);
- for (size_t i = 0; i < s1.size(); i++)
- {
- f << s1[i];
- if (i + 1 != s1.size())f << endl;
- }
- f.close();
- }
- }
- p = "C:\\1\\List1.txt";
- hash_sum(p);
- f1.open("C:\\1\\List.txt");
- vector<string>fir = init();
- f1.close();
- f1.open(p);
- vector<string>sec = init();
- f1.close();
- for (size_t i = 0; i < fir.size(); i++)
- {
- if (fir[i] == sec[i])cout << "Correct" << endl;
- else cout << "Incorrect" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement