mephisto_x
Grünschnabel
Halli hallo, bin neu hier und bin auf der Suche nach Tricks schon des Öfteren hier gelandet, deshalb dachte ich mir, ich könnte hier mal meine sozusagen programmiertechnische Jungfernfahrt zelebrieren . Ich wollte einfach mal Anregungen haben, was ich noch so einfügen könnte und wie ich eventuell etwas verbessern könnte, da hier ja Einige kompetente User angemeldet sind.
also lange Rede kurzer Sinn hier ist der Code
also lange Rede kurzer Sinn hier ist der Code
Code:
//
// decodehlpr.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
char keycrypt(char, char);
char keydecrypt(char, char);
bool isAllowed(char Alphat)
{
for(int count=97; count<=122; count++)
{
if (Alphat == char(count))
{
return true;
}
}
cout << "Please enter a letter! ";
return false;
}
char keycrypt(char PresentChar, char entered) //97-122 ASCII-Symbols a-z
{
char CryptedChar;
int UsedAlphabet=0;
if(entered!='z')
{
UsedAlphabet = (int(entered)-97);
}
if ((int(PresentChar)+UsedAlphabet)<=122)
{
CryptedChar=char(int(PresentChar)+UsedAlphabet);
}
else
{
CryptedChar=char(int(PresentChar)+UsedAlphabet-26);
}
return CryptedChar;
}
char keydecrypt(char PresentChar, char entered) //97-122 ASCII-Symbols a-x
{
char DecryptedChar;
int UsedAlphabet=0;
if(entered!='z')
{
UsedAlphabet = (int(entered)-97);
}
if ((int(PresentChar)-UsedAlphabet)>=97)
{
DecryptedChar=char(int(PresentChar)-UsedAlphabet);
}
else
{
DecryptedChar=char(int(PresentChar)-UsedAlphabet+26);
}
return DecryptedChar;
}
int main()
{
cout << "Welcome!" << endl;
cout << "Please chose either code [d]ecryption or code [e]ncryption\n";
string Text;
string KeyWord;
string Crypted;
string DeCrypted;
ofstream file("Test.txt", ios::app);
string buffer;
char chosen;
cin >> chosen;
switch(chosen)
{
case 'd':
cout << "Please enter the crypted code, which has to be decrypted!";
cin >> Text;
DeCrypted=Text;
cout << endl << "Now please enter the used keyword! (consisting of letters a to z)" << endl;
cin >> KeyWord;
DeCrypted = Text;
if(Text.size()>KeyWord.size())
{
int i=0;
do
{
KeyWord+=KeyWord[i];
i++;
}
while(KeyWord.size()!=Text.size());
}
for(int i=0; i<=Text.size()-1; i++)
{
DeCrypted[i]=keydecrypt(Text[i],KeyWord[i]);
}
if(file.is_open())
{
while(!file.eof())
{
file << DeCrypted << endl;
file << "naechster Teil: " << endl;
file.close();
}
}
else cout << "Unable to open the file";
break;
case 'e':
cout << "Please enter the clear text, which you want to encrypt with CAESAR 1 alphabet!" << endl;
cin >> Text;
Crypted=Text;
cout << endl << "Now please enter your favourite keyword! (consisting of letters a to z)" << endl;
cin >> KeyWord;
Crypted = Text;
if(Text.size()>KeyWord.size())
{
int i=0;
do
{
KeyWord+=KeyWord[i];
i++;
}
while(KeyWord.size()!=Text.size());
}
for(int i=0; i<=Text.size()-1; i++)
{
Crypted[i]=keycrypt(Text[i],KeyWord[i]);
}
cout << Crypted;
while(!file.eof())
{
file << Crypted << endl;
file.close();
}
break;
default:
cout << "Please either enter d or e!";
}
system("pause");
return 0;
}