Advertisement
Combreal

cesarCrypto.cpp

Jul 18th, 2020
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main(void)
  7. {
  8.     string sentence, alphabet, newAlphabet, rest, crypt;
  9.     int shift = 0, choice = 0;
  10.     alphabet = "abcdefghijklmnopqrstuvwxyz";
  11.     cout << "Voulez-vous chiffrer (1) ou d\202chiffrer (2) : ";
  12.     cin >> choice;
  13.     if (choice == 1)
  14.     {
  15.         cout << "Entrez la phrase \205 chiffrer : ";
  16.         cin >> sentence;
  17.         cout << "Entrez le chiffre de C\202sar : ";
  18.         cin >> shift;
  19.         newAlphabet = alphabet.substr(shift);
  20.         rest = alphabet.substr(0, shift);
  21.         newAlphabet += rest;
  22.         for(int i = 0; i < sentence.length(); ++i)
  23.         {
  24.             size_t pos = alphabet.find(sentence.at(i));
  25.             crypt += newAlphabet.at(pos);
  26.         }
  27.     }
  28.     else if (choice == 2)
  29.     {
  30.         cout << "Entrez la phrase \205 d\202chiffrer : ";
  31.         cin >> sentence;
  32.         cout << "Entrez le chiffre de C\202sar : ";
  33.         cin >> shift;
  34.         newAlphabet = alphabet.substr(shift);
  35.         rest = alphabet.substr(0, shift);
  36.         newAlphabet += rest;
  37.         for(int i = 0; i < sentence.length(); ++i)
  38.         {
  39.             size_t pos = newAlphabet.find(sentence.at(i));
  40.             crypt += alphabet.at(pos);
  41.         }
  42.     }
  43.     else
  44.     {
  45.         cout << "Vous n'avez pas rentr\202 1 ou 2." << endl;
  46.         return 0;
  47.     }
  48.     cout << crypt << endl;
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement