Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <iostream>
- #include <string>
- #include <thread>
- #include <vector>
- void culc(std::string* s1, int begin, int end) {
- for (int i = begin; i < end; i++) {
- (*s1)[i] = 'a' + ((*s1)[i] + 3 - 'a') % 26;
- }
- }
- void CaesarEncrypt(std::string* s) {
- std::thread thread;
- int k = 1;
- int k1 = 2;
- std::vector<std::thread*> threads;
- int N = thread.hardware_concurrency();
- auto tr = new std::thread(culc, std::ref(s), 0, s->size() / N);
- threads.push_back(tr);
- for (int i = 0; i < N - 1; i++) {
- if (i == N - 2) {
- auto t = new std::thread(culc, std::ref(s), s->size() / N * k, s->size());
- threads.push_back(t);
- } else {
- auto t = new std::thread(culc, std::ref(s), s->size() / N * k,
- s->size() / N * k1);
- k1++;
- k++;
- threads.push_back(t);
- }
- }
- for (int i = 0; i < N; i++) {
- std::cout << threads[i]->get_id() << std::endl;
- threads[i]->join();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement