c++ - 施奈尔河豚

标签 c++ c encryption blowfish

有人可以向我展示 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/

相关文章:

c++ - 模板 vector 到 vector 转换函数

c - 使用 C 中的排序字典对字符串进行拼写检查

c - 如何在C中将 "\003"转换为int

ruby - 在 Ruby 中加密/解密 3DES

c++ - 与 Worklight 静态库的符号冲突

c++ - 定义宏时 `(...)`是什么意思?

c++ - 系统找不到在 Visual Studio 2012 上指定的文件

c - Ascii 转换错误

c# - 使用 .NET 4.5 (System.IdentityModel)/WIF 解密 SAML 2 断言

java - 谁能告诉我在使用 RSA 的图像加密和解密过程中犯了什么错误