Advertisement
wierzba100

szyfr vigenera

Dec 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. //szyfr vigenera
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main () {
  7.     int i, j;
  8.     string slowo, klucz;
  9.     char tab[26][26];
  10.     for (i=0; i<26; i++) {
  11.         for (j=0; j<26; j++)
  12.     {
  13.         if (i+j+65>90)
  14.             tab[i][j]=(char)j+i+65-26;
  15.         else
  16.             tab[i][j]=(char)j+i+65;
  17.  
  18.  
  19.         cout << tab[i][j] << " ";
  20.  
  21.     }
  22.     cout << endl;
  23.     }
  24. //---------------
  25. cin >> slowo;
  26. cin >> klucz;
  27.  
  28. for (i=0,j=0; i<slowo.size(); i++,j++){
  29.     if (j==klucz.size())
  30.         j=0;
  31.     slowo[i]=tab[slowo[i]-65][klucz[j]-65];
  32.  
  33. }
  34. cout << "Zakodowany " << slowo << endl;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement