Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <map>
- using namespace std;
- int main() {
- ifstream keyStream("key.txt");
- vector<int> offsets;
- string temp;
- while (keyStream >> temp){
- int offsetSum = 0;
- for (int i = 0; i < temp.size(); ++i) {
- offsetSum += temp[i];
- }
- offsets.push_back(offsetSum);
- }
- ifstream in("input.txt");
- ofstream encrypted("encrypted.txt");
- map<char, map<char, int>> encryptionsOfChars;
- printf("Encrypted content(encrypted.txt):\n");
- while (getline(in, temp)){
- for (int i = 0; i < temp.size(); ++i) {
- char nChar = (temp[i] + offsets[i % offsets.size()]) % 256;
- encryptionsOfChars[temp[i]][nChar]++;
- temp[i] = nChar;
- }
- encrypted << temp << endl;
- cout << temp << endl;
- }
- ifstream encryptedIn("encrypted.txt");
- ofstream decrypted("decrypted.txt");
- printf("Decrypted content(decrypted.txt):\n");
- while (getline(encryptedIn, temp)){
- for (int i = 0; i < temp.size(); ++i) {
- temp[i] = (temp[i] - offsets[i % offsets.size()]) % 256;
- }
- decrypted << temp << endl;
- cout << temp << endl;
- }
- bool repeat = true;
- while (repeat){
- char symbol;
- printf("symbol to examine: ");
- cin >> symbol;
- for (auto i = encryptionsOfChars[symbol].begin(); i !=encryptionsOfChars[symbol].end() ; ++i) {
- printf("\t%d(%c)\t: %d\n", i -> first, i ->first, i -> second);
- }
- printf("continue? (0 / 1): ");
- cin >> repeat;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement