Advertisement
wojtas626

[C++] JiMP lab2 Polibiusz

Mar 9th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char **args)
  8. {
  9.     ifstream inputFile(args[1]);
  10.  
  11.     if (!inputFile)
  12.     {
  13.         cout << "Blad odczytu pliku!";
  14.         return 0;
  15.     }
  16.     else
  17.     {
  18.         ofstream outputFile (args[2], ios_base::in | ios_base::app);
  19.         if (!outputFile)
  20.         {
  21.             cout << "Blad pliku wyjsciowego!";
  22.             return 0;
  23.         }
  24.         else
  25.         {
  26.             char cipher[5][5];
  27.  
  28.             for (int i = 0; i < 2; i++)
  29.             {
  30.                 for (int j = 0; j < 5; j++)
  31.                 {
  32.                     cipher[i][j] = 65 + i*5 + j;
  33.                 }
  34.             }
  35.             cipher[1][4] = 'K';
  36.             for (int i = 2; i < 5; i++)
  37.             {
  38.                 for (int j = 0; j < 5; j++)
  39.                 {
  40.                     cipher[i][j] = 66 + i*5 + j;
  41.                 }
  42.             }
  43.  
  44.  
  45.  
  46.             if (strcasecmp(args[3], "1") == 0)
  47.             {
  48.                 // szyfrowanie
  49.                 string input;
  50.                 inputFile >> input;
  51.  
  52.  
  53.  
  54.  
  55.                 for (int i = 0; i < input.length(); i++)
  56.                 {
  57.                     if (input[i] == 'J')
  58.                     {
  59.                         outputFile << "24 ";
  60.                     }
  61.                     else
  62.                     {
  63.                         for (int j = 0; j < 5; j++)
  64.                         {
  65.                             for (int k = 0; k < 5; k++)
  66.                             {
  67.                                 if (input[i] == cipher[j][k])
  68.                                 {
  69.                                     outputFile << i+1 << j+1 << " ";
  70.                                 }
  71.                             }
  72.                         }
  73.                     }
  74.  
  75.                 }
  76.             }
  77.             else if (strcasecmp(args[3], "0") == 0)
  78.             {
  79.  
  80.                 // deszyfrowanie
  81.  
  82.             }
  83.             else
  84.             {
  85.                 cout << "Blad argumentu trybu pracy!";
  86.                 return 0;
  87.             }
  88.         }
  89.         outputFile.close();
  90.     }
  91.  
  92.     inputFile.close();
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement