编写一个简单的加密程序:输入四位整数,按照以下加密算法处理后,生成加密后的四位整数输出。 加密算法:

2025-04-19 10:34:55
推荐回答(1个)
回答1:

//原理: a异或b异或b 等于 a

//b就是密码

# include
int __stdcall wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPWSTR lpCmdLine, __in int nShowCmd )
{
int numInput[4] = {1, 2, 3, 4}; //输入数据
int key[4] = {6, 2, 9, 8}; //密码
int enp[4], disenp[4]; //加密与解密后的数据
for(int i = 0; i < 4; ++i)
{
enp[i] = numInput[i] ^ key[i];
disenp[i] = enp[i] ^ key[i];
}
wchar_t strDsp[56];
wsprintf(strDsp, L"原数据%d:%d:%d:%d", numInput[0], numInput[1], numInput[2], numInput[3]);
::MessageBox(::GetForegroundWindow(), strDsp, strDsp, 0);
wsprintf(strDsp, L"加密后%d:%d:%d:%d", enp[0], enp[1], enp[2], enp[3]);
::MessageBox(::GetForegroundWindow(), strDsp, strDsp, 0);
wsprintf(strDsp, L"解密后%d:%d:%d:%d", disenp[0], disenp[1], disenp[2], disenp[3]);
::MessageBox(::GetForegroundWindow(), strDsp, strDsp, 0);
return 0;
}