#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

// Funkcja szyfrująca metodą Cezara
string caesarCipher(const string &text, int shift) {
    string result = "";
    
    for (char c : text) {
        if (isalpha(c)) {
            char base = islower(c) ? 'a' : 'A';
            result += char(int(base + (c - base + shift) % 26));
        } else {
            result += c; // nie zmieniamy znaków nieliterowych
        }
    }
    return result;
}

// Funkcja szyfrująca metodą przestawieniową
string transpositionCipher(const string &text, const vector<int> &key) {
    int n = key.size();
    string result(text.size(), ' ');

    for (size_t i = 0; i < text.size(); ++i) {
        result[i] = text[key[i % n] - 1];
    }
    return result;
}

int main() {
    string text;
    int shift;
    vector<int> key;

    // Przykład szyfrowania metodą Cezara
    cout << "Podaj tekst do zaszyfrowania metodą Cezara: ";
    getline(cin, text);
    cout << "Podaj przesunięcie: ";
    cin >> shift;
    string encryptedCaesar = caesarCipher(text, shift);
    cout << "Zaszyfrowany tekst (Cezar): " << encryptedCaesar << endl;

    // Przykład szyfrowania metodą przestawieniową
    cout << "Podaj tekst do zaszyfrowania metodą przestawieniową: ";
    cin.ignore(); // Ignorujemy nową linię po cin
    getline(cin, text);
    cout << "Podaj długość klucza: ";
    int keySize;
    cin >> keySize;
    cout << "Podaj klucz (pozycje): ";
    key.resize(keySize);
    for (int i = 0; i < keySize; ++i) {
        cin >> key[i];
    }
    string encryptedTransposition = transpositionCipher(text, key);
    cout << "Zaszyfrowany tekst (przestawieniowa): " << encryptedTransposition << endl;

    return 0;
}



    

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: