Advertisement
j0h

Caeser

j0h
Oct 17th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <sstream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. void lpp (string msg){
  9.  string imsg = msg;
  10.  const char* E = "echo \"";
  11.  const char* L = "\" | lp  ";  
  12.  string total = string(E) + string(imsg) + string(L);
  13.  //cout << total << "\n\n";
  14.  const char* cmd = total.c_str();
  15.  system(cmd);
  16. }
  17.  
  18. int main(int argc, char** argv)
  19. {
  20.     int opt;
  21.     string input = "";
  22.     bool flagA = false;
  23.     bool flagB = false;
  24.     // Retrieve the (non-option) argument:
  25.     if ( (argc <= 1) || (argv[argc-1] == NULL) || (argv[argc-1][0] == '-') )
  26.        {    // there is NO input...
  27.            cerr << "No argument provided!" << endl;
  28.            //return 1;
  29.        }
  30.     else
  31.        {  // there is an input...
  32.           input = argv[argc-1];
  33.        }
  34.  
  35.     // Debug:
  36.     cout << "input = " << input << endl;
  37.     // Shut GetOpt error messages down (return '?'):
  38.     opterr = 0;
  39.     // Retrieve the options:
  40.     while ( (opt = getopt(argc, argv, "ab")) != -1 ) {  // for each option...
  41.         switch ( opt ) {
  42.             case 'a':
  43.                     flagA = true;
  44.                 break;
  45.             case 'b':
  46.                     flagB = true;
  47.                 break;
  48.             case '?':  // unknown option...
  49.                     cerr << "Unknown option: '" << char(optopt) << "'!" << endl;
  50.                 break;
  51.         }
  52.     }
  53.  
  54. //read number associated with the options flag for bit shifting.    
  55. stringstream strValue;
  56. strValue << argv[2];
  57. int intValue;
  58. strValue >> intValue;
  59.  
  60.  
  61. string::iterator it;
  62. it = input.begin();
  63. string msg = "";
  64. for (int index = 0; it < input.end(); ++index)
  65.     {
  66.      int x = (int)*it - intValue;
  67.      //output the character values shifted over by the number  in argument argv[2]
  68.  
  69.          if ((x<65) || (x>90))
  70.               x=x+26;
  71.  
  72.          if ((x > 90)||(x<65))
  73.             {
  74.                 cout << " ";  
  75.                 msg += " ";
  76.                 ++it;
  77.              }
  78.  
  79.           else
  80.              {  
  81.                 char z = (char)x;      
  82.                 cout << z;
  83.                 msg += z;
  84.                 ++it;
  85.               }
  86.      }
  87.          if (flagA == true)
  88.               lpp(msg);
  89.                
  90.          if (flagB == true)
  91.               cout << "I hope you enjoyed my program\n";
  92.  
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement