#include
#include
using namespace std;
int main()
{
setlocale(LC_CTYPE, "Russian_Russia.1251");
string str;
char * buf;
int size;
cout << endl << " Введите строку: ";
setlocale(LC_CTYPE, "English_United States.866");
getline(cin, str);
size = str.size() + 1;
buf = new char [size];
strcpy(buf, str.c_str());
for (int n = 0; n < size - 1; n++)
{
buf[n] += 3;
cout << buf[n];
}
cin.get(); cin.get();
delete[] buf;
return 0;
}
#include < stdio.h >
#include < stdlib.h >
#include < ctype.h >
char *CaesarCipher (char *str)
{
int i, c;
for (i = 0; str[ i ]; i++)
{
c = tolower(str[ i ]);
if ( c == 'x' ) str[ i ] = 'a';
else if ( c == 'y' ) str[ i ] = 'b';
else if ( c == 'z' ) str[ i ] = 'c';
else if ( c == ' ' ) str[ i ] = ' ';
else str[ i ] = c + 3;
}
return str;
}
int main (void)
{
/* тестовые строки взяты с Wiki
http://en.wikipedia.org/wiki/Caesar_cipher */
char str[ ] = "the quick brown fox jumps over the lazy dog";
char test[ ] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
printf("PLAIN : %s\n", test);
printf("CIPHER: %s\n\n", CaesarCipher( test ));
printf("Plaintext : ");
puts(str);
printf("Ciphertext : ");
puts(CaesarCipher( str ));
system("pause > nul");
return 0;
}