Det er udvikleren.dk der laver "sjov" med koden.
Prøver lige igen:
#include <iostream>
#include <string>
std::string Crypt(const std::string& aIn)
{
static const char Arr1[] = "klmnopqrstuvwxyzabcdefghij";
static const char Arr2[] = "KLMNOPQRSTUVWXYZABCDEFGHIJ";
std::string::size_type j;
std::string Out;
for(j = 0; j < aIn.size(); j++)
{
char ch = aIn[ j ];
if(aIn[ j ] >= 'a' && aIn[ j ] <= 'z')
Out += Arr1[ch - 'a'];
else if(aIn[ j ] >= 'A' && aIn[ j ] <= 'Z')
Out += Arr2[ch - 'A'];
else
Out += ch;
}
return Out;
}
std::string Decrypt(const std::string& aIn)
{
static const char Arr1[] = "qrstuvwxyzabcdefghijklmnop";
static const char Arr2[] = "QRSTUVWXYZABCDEFGHIJKLMNOP";
std::string::size_type j;
std::string Out;
for(j = 0; j < aIn.size(); j++)
{
char ch = aIn[ j ];
if(aIn[ j ] >= 'a' && aIn[ j ] <= 'z')
Out += Arr1[ch - 'a'];
else if(aIn[ j ] >= 'A' && aIn[ j ] <= 'Z')
Out += Arr2[ch - 'A'];
else
Out += ch;
}
return Out;
}
int main()
{
std::string Line;
std::cout << "Skriv noget: ";
std::cout.flush();
std::getline(std::cin, Line);
std::string Crypted = Crypt(Line);
std::cout << "Krypteret: " << Crypted << std::endl;
std::string Decrypted = Decrypt(Crypted);
std::cout << "Dekrypteret: " << Decrypted << std::endl;
}
Indlæg senest redigeret d. 16.10.2006 19:59 af Bruger #4996