/*****************************************************************
Programm:        Verschluesselung
Dateien:         code.cpp
Funktionen:      main(): Eingabe des Textes
                 ausgabe(): Ausgabe des Textfelds
                 code(): Verschluesselung des Textes
Beschreibung:    Verschluesselung eines Textes
Author:          Michael Hoeppenstein
Version:         1.00        08.10.2017        (mh)
******************************************************************/

#include <iostream>
#include <cctype>

using namespace std;

void code(char text[]);
void ausgabe(char text[]);

int main()
{
        char text[101];
        cout << "Text eingeben (maxiamle Laenge 100 Zeichen): ";
        cin.get(text, 100);
        cout << "\n\nDer unverschluesselte Text:\t";
        ausgabe(text);
        code (text);
        cout << "\n\nDer verschluesselte Text:\t";
        ausgabe(text);
        return 0;
}

void ausgabe(char text[])
{
        for (int i=0; text[i] != '\0'; i++)
        {
                cout << text[i];
        }
}

void code(char text[])
{
        char abism[] = "abcdefghijklm";
        char AbisM[] = "ABCDEFGHIJKLM";
        char nbisz[] = "nopqrstuvwxyz";
        char NbisZ[] = "NOPQRSTUVWXYZ";

for (int i=0; text[i] != '\0'; i++)
{
        if (isalpha(text[i]))
        {
                if (isupper(text[i]))
                {
                        for (int j=0; AbisM[j] != '\0'; j++)
                        {
                                if (text[i] == AbisM[j])
                                {
                                        text[i] += 13;
                                        break;
                                }
                                else if (text[i] == NbisZ[j])
                                {
                                        text[i] -= 13;
                                        break;
                                }
                        }
                }
                else if (islower(text[i]))
                {
                        for (int j=0; abism[j] != '\0'; j++)
                        {
                                if (text[i] == abism[j])
                                {
                                        text[i] += 13;
                                        break;
                                }
                                else if (text[i] == nbisz[j])
                                {
                                        text[i] -= 13;
                                        break;
                                }
                        }
                }
        }
}
}
