T
So, ich habe es nun einmal mit strings versucht, das Programm gibt mir eigentlich schon fast wieder den richtigen Satz heraus, wenn ich ihn mit dem richtigen passwort dechiffriere. Das Problem ist aber, dass manchmal trotzdem irgendwie komische Zeichen vorkommen, ich blicke einfach nicht mehr durch.
[code]
#include <iostream>
#include <cmath>
#include <climits>
#include <cstring>
using namespace std;
//*****************************************************************************
//Dieses Register führt eine TestArray ein, um länge anzupassen.
//*****************************************************************************
int main()
{
string phrase; //dient zur stringkuerzung
cout << "Geben sie einen zu kodierenden Satz ein:\n";
cout << "\n";
getline (cin,phrase);
int q = phrase.length();
string password; //dient zur stringkuerzung
cout << "\n";
cout << "Geben sie ein Passwort ein:\n";
cout << "\n";
getline (cin,password);
int r = password.length();
string password2;
for (int passwordzurueck = 0; passwordzurueck < q ;passwordzurueck++)
{
password2[passwordzurueck] = 0;
}
//*****************************************************************************
//Dieses Register enthält die Umrechnung.
//*****************************************************************************
for (int i = 0; i < q ; i++)
{
if (isalpha(phrase[i]))
{
phrase[i] = (phrase[i] - 32);
}
else
{
;
}
}
for (int j = 0; j < r ; j++)
{
if (isalpha(password[j]))
{
password[j] = password[j] - 32;
}
else
{
;
}
}
//*****************************************************************************
//Dieses Register enthaelt die Streckung des Passwortes auf die Länge von phrase
//*****************************************************************************
if (q<=r)
{
for (int s =0; s<q; s++)
{ password2[s] = password[s];
}
}
if (r<q)
{
for (int t = 0; t<q ;)
{
for(int t1 = 0 ; t1<r && t<q ;)
{
password2 = password2 + password[t1];
t++;
t1++;
}
}
}
cout << "\n";
//*****************************************************************************
//Dieses Register enthaelt die Funktion.
//*****************************************************************************
for (int h = 0; h < q ; h++)
{
if (isalpha(phrase[h]))
{
phrase[h] = ((phrase[h]-65) + ((password2[h]-65)%26))+65;
}
else
{
;
}
}
cout << phrase;
cout << "\n";
//*****************************************************************************
//Dieses Register enthaelt die Streckung des Passwortes auf die Länge von phrase
//*****************************************************************************
cout << "\n";
cout << "Bitte geben sie das Passwort ein:\n";
cout << "\n";
string password3;
getline (cin,password3);
if (q<=r)
{
for (int s =0; s<q; s++)
{ password3[s] = password[s];
}
}
if (r<q)
{
for (int t = 0; t<q ;)
{
for(int t1 = 0 ; t1<r && t<q ;)
{
password3 = password3 + password[t1];
t++;
t1++;
}
}
}
cout << "\n";
//*****************************************************************************
//Dieses Register enthaelt die Rueckfunktion
//*****************************************************************************
for (int h1 = 0; h1 < q ; h1++)
{
if (isalpha(phrase[h1]))
{
phrase[h1] = ((phrase[h1]-65) - ((password3[h1]-65)%26))+65;
}
else
{
;
}
}
cout << phrase;
cin.get();
return 0;
}