Advertisement
informaticage

Caesar with args parameters bribro

Apr 3rd, 2021
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. char encode(char c, int key) {
  6.   std::vector<char> alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
  7.                                 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
  8.                                 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  9.   return alphabet[((c - 65) + key) % (alphabet.size())];
  10. }
  11.  
  12. char decode(char c, int key) { return encode(c, 26 - key); }
  13.  
  14. std::string full_decode(std::string s, int key) {
  15.   for (int i = 0; i < s.length(); i++) {
  16.     if (s[i] != ' ')
  17.       s[i] = decode(s.at(i), key);
  18.   }
  19.  
  20.   return s;
  21. }
  22.  
  23. std::string full_encode(std::string s, int key) {
  24.   for (int i = 0; i < s.length(); i++) {
  25.     if (s[i] != ' ')
  26.       s[i] = encode(s.at(i), key);
  27.   }
  28.  
  29.   return s;
  30. }
  31.  
  32. // (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
  33. // (0 1 2 3 4                                        25)
  34. int main(int argc, char **args) {
  35.   using namespace std;
  36.  
  37.   if(argc != 2) {
  38.     cout << "Utilizzo del programma: crypta.exe nomefile.txt" << endl;
  39.     return -1;
  40.   }
  41.  
  42.   ofstream fout;
  43.   ifstream fin;
  44.   fin.open(args[1]);
  45.   fout.open("output.txt");
  46.  
  47.   string file_input = "";
  48.  
  49.   while (!fin.eof()) {
  50.     string temp;
  51.     fin >> temp;
  52.     file_input += temp + " ";
  53.   }
  54.  
  55.   string s = full_encode(file_input, 7);
  56.   // cout << endl << s << endl;
  57.   // s = full_decode(s, 7);
  58.   // cout << endl << s << endl;
  59.   fout << s;
  60.   fout.close();
  61.   return 0;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement