Вход на сайт
C++ Решить задачку?
388
NEW 17.11.08 11:02
#include <iostream>
#include <string>
using namespace std;
string encrypt(string text, string key)
{
string result;
// Here something is missing...
return result;
}
/** This is the entry point of the program. */
int main(int argc, char* argv[])
{
string text = "Dies ist irgendein Text.";
string key = "irgendein Passwort";
// Here something is missing...
return 0;
}
#include <string>
using namespace std;
string encrypt(string text, string key)
{
string result;
// Here something is missing...
return result;
}
/** This is the entry point of the program. */
int main(int argc, char* argv[])
{
string text = "Dies ist irgendein Text.";
string key = "irgendein Passwort";
// Here something is missing...
return 0;
}
NEW 17.11.08 13:04
в ответ dzmitriy22db 17.11.08 11:02
Должно быть, что то типа..
В ф-ции encrypt нужно реализовать, какой-либо алгоритм шифрования.. В тривиальнейшем случае посимвольный XOR текста и ключа. Далее
// Here something is missing...
string strEncripted = encrypt(text, key);
printf("Encrypted text: %s", strEncripted.c_str());
return 0;
В ф-ции encrypt нужно реализовать, какой-либо алгоритм шифрования.. В тривиальнейшем случае посимвольный XOR текста и ключа. Далее
// Here something is missing...
string strEncripted = encrypt(text, key);
printf("Encrypted text: %s", strEncripted.c_str());
return 0;
17.11.08 13:48
в ответ dzmitriy22db 17.11.08 11:02
А вот и пример функции encrypt :
В ответ на:
string encrypt(string text, string key)
{
std::string::iterator iterText;
std::string::iterator iterKey;
iterKey=key.begin();
for (iterText=text.begin();iterText!=text.end();iterText++)
{
if (iterKey == key.end())
iterKey=key.begin();
char ch = ((((*iterText-' ') + (*iterKey-' ')) % ('~' - ' ')) + ' ');
result.push_back( ch );
iterKey++;
}
}
string encrypt(string text, string key)
{
std::string::iterator iterText;
std::string::iterator iterKey;
iterKey=key.begin();
for (iterText=text.begin();iterText!=text.end();iterText++)
{
if (iterKey == key.end())
iterKey=key.begin();
char ch = ((((*iterText-' ') + (*iterKey-' ')) % ('~' - ' ')) + ' ');
result.push_back( ch );
iterKey++;
}
}