Witam mam taki problem z zadaniem
Podaj specyfikację i skonstruuj algorytm w postaci programu szyfrujący i deszyfrujący wiadomość wczytaną z klawiatury metodą płotową dla wysokości 2.
mam takie cos deszyfrujacy dla wyskosci 3 i szyfrujacy dla 3 ale nwm jak zrobic to samo dla 2.
deszyfrujacy
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
string deszyfruj (string tekst)
{
string wynik;
int dl = tekst.size();
wynik = tekst;
int j = 0;
for(int i=0;i<dl;i+=4) wynik[i] = tekst[j++];
for(int i=1;i<dl;i+=2) wynik[i] = tekst[j++];
for(int i=2;i<dl;i+=4) wynik[i] = tekst[j++];
wynik += (char) 0;
return wynik;
}
int main(int argc, char *argv[])
{
string tekst;
cout<<"Wpisz kryptogram ,ktory chcesz rozszyfrowac"<<endl;
cin>>tekst;
cout<<"tekst jawny"<<endl;
cout <<deszyfruj(tekst) << endl;
system ("pause");
return 0;
}