게임에서 플레이어의 데이터를 암호화하고 암호 해독하는 매우 간단한 시저 알고리즘을 만들려고 노력 중입니다. 그러나 이상한 결과를 얻고 있습니다. 알고리즘의 작업은 간단합니다. ascii 테이블의 문자를 뒤로 이동합니다.C++ 간단한 시저 암호화 알고리즘
std::string Encrypt(std::string in,int key)
{
const char* chars=in.data();
char* newchar=(char*)malloc(sizeof(char)*in.length());
for(int c=0;c<in.length();c++)
{
newchar[c]=char(((int)chars[c])+key);//I suspect somewhere here is the problem
}
std::string out(newchar);
return out;
}
LOGI("encrypt:%s",Encrypt("hello",10).data());
LOGI("decrypt:%s",Encrypt(Encrypt("hello",10),-10).data());
출력 :
encrypt:[email protected]
decrypt:hellok
내가 암호화에 대해 잘 몰라요 내가 아스키 전체 문자 것은 C에서 작동하는 방법에 대해 덜 알고
왜 게임의 텍스트 부분을 해독합니까? 그렇지 않은 경우 왜 기존의 라이브러리에서 최신 암호화 기술을 사용하지 않는 것이 아닙니까? 편지 대체 알고리즘은 오늘날의 어떤 보호에도 유용하지 않습니다. 지옥, 사람들은 재미있게 [신문에서] (http://en.wikipedia.org/wiki/Cryptogram) 그들을합니다. –
'sizeof (char) == 1', 정의에 따라. – qdii
당신은'newchar'을 해방해야합니다. 'out'은 문자열의 복사본을 만듭니다. – qdii