-4

有人可以向我展示 Schneier 的 Blowfish 代码 ( http://www.schneier.com/code/bfsh-sch.zip )的示例用法,即使用 C 或 C++ 使用给定密钥加密和解密字符串吗?

提前致谢。

编辑:这不是家庭作业。

4

1 回答 1

2

这是一个测试

#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

于 2011-06-16T02:48:50.340 回答