Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <string>
- #include <thread>
- #include <vector>
- const size_t THREADS = std::thread::hardware_concurrency();
- void CaesarEncryptPart(std::string* s) {
- for (char& c : *s) c = 'a' + (c + 3 - 'a') % 26;
- }
- void CaesarEncrypt(std::string* s) {
- std::vector<std::thread> threads;
- if (s->length() % 2 != 0) s = s + ' ';
- size_t len = s->length() / THREADS;
- size_t n = std::min(s->length(), THREADS);
- size_t l = 0;
- size_t r = len;
- for (size_t i = 0; i < n; i++) {
- std::string tmp = s->substr(l, r);
- threads.emplace_back(std::thread(CaesarEncryptPart, &tmp));
- l = l + len;
- r = r + len;
- }
- for (size_t i = 0; i < threads.size(); i++) {
- threads[i].join();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement