Odpowiedź :
Odpowiedź:
#include <iostream>
#include <string>
using namespace std;
string cipher(string text, int key)
{
string alphabet = "abcdefghijklmnopqrstuvqyz"; //25 znakow
string result = "";
for (int i = 0; i < text.size(); i++)
{
if (alphabet.find(text[i]) + key <= 24)
{
text[i] = alphabet[alphabet.find(text[i]) + key];
result += text[i];
}
else
{
text[i] = alphabet[(alphabet.find(text[i]) + key) % 25];
result += text[i];
}
}
return result;
}
int main(int argc, char const *argv[])
{
string text;
cout << "Podaj tekst do zaszyfrowania" << endl;
cin >> text;
int key;
cout << "Podaj klucz wobec ktorego bedziemy szyfrowac " << endl;
cin >> key;
cout << "Zaszyfrowana wiadomosc " << cipher(text, key);
return 0;
}
Wyjaśnienie:
Powinno być dobrze. Tylko może być o 1 literkę w przód w tył niedokładny, bo już jestem zmęczony i umieram. Tam posprawdzaj sobie i ewentualnie zamień 24 na 25 lub odwrotnie. I jak czegoś nie rozumiesz jak działa to pytaj :)