有人可以向我展示 Schneier 的 Blowfish 代码 ( http://www.schneier.com/code/bfsh-sch.zip ) 的示例用法,即使用给定 key 在 C 或 C++ 中加密和解密字符串吗?
提前致谢。
编辑:这不是家庭作业。
最佳答案
这是一个测试
#include <stdio.h>
#include "blowfish.h"
#include <string.h>
int main(void)
{
unsigned long xl = 1, xr = 2;
char key[] = "Hello";
/* NoErr is defined as 0 in the blowfish.c file */
if (opensubkeyfile () != 0)
{
printf ("\nCannot open subkey file");
perror ("Exit");
printf ("\n");
return 1;
};
InitializeBlowfish (key, 7);
Blowfish_encipher (&xl, &xr);
printf("\n%x %x", xl, xr);
Blowfish_decipher (&xl, &xr);
printf("\n%x %x", xl, xr);
if ((xl == 1) && (xr == 2))
{
printf("\nDecipher OK.");
}
else
{
printf("\nDecipher Fail\n");
}
printf ("\n");
return 0;
}
请确保头文件名的字符大小写。另请注意文件名 blowfish.dat
是正确的。
另请参阅以下页面中的 Paul Kocher 的实现:http://www.schneier.com/blowfish-download.html
关于c++ - 施奈尔河豚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6366243/