施奈尔的河豚

Schneier's Blowfish

本文关键字:河豚 施奈尔      更新时间:2023-10-16

有人能给我看一下Schneier的Blowfish代码的用法示例吗(http://www.schneier.com/code/bfsh-sch.zip),即用给定的密钥加密和解密字符串,用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 Failn");
  }
  printf ("n");
  return 0;
}

请确保头文件名的大小写为字符。还要注意,文件名blowfish.dat是正确的。

还可以从本页查看Paul Kocher的实施:http://www.schneier.com/blowfish-download.html