【问题标题】:Schneier's Blowfish [closed]施奈尔河豚[关闭]
【发布时间】:2011-09-16 00:17:27
【问题描述】:

谁能给我看一个 Schneier 的 Blowfish 代码 (http://www.schneier.com/code/bfsh-sch.zip) 的用法示例,即用 C 或 C++ 用给定的密钥加密和解密字符串?

提前致谢。

编辑:这不是家庭作业。

【问题讨论】:

  • 你自己试过了吗?它没有工作吗?你尝试了什么?
  • 不是家庭作业——只是个人项目。我需要为我正在从事的(个人)项目实施加密,但除非需要,否则我宁愿不详细了解加密方法。大概我只需要一个 Encrypt(string, key) 和 Decrypt(string, key) 函数来实现加密,这就是我试图摆脱 Blowfish 的全部。
  • 哇,为什么这个问题的评分很差?这是一个诚实的问题,我觉得我在最初研究它时做了相当多的努力。我想如果我花一天时间研究 Blowfish,我可以自己解决这个问题,但对于了解他们的东西的好心人来说,向我展示如何使用它并节省我一些时间似乎很简单。跨度>
  • 如果它应该可靠地工作并且您不想学习密码学,为什么不直接使用高质量的免费库之一,例如 bcrypt++、beecrypt、mcrypt 或 openssl?跨度>
  • @JonaGik:因为基本上简而言之,您的问题类似于“在此处下载一些代码并弄清楚它是如何工作的。然后回复我”。

标签: c++ c encryption blowfish


【解决方案1】:

这是一个测试

#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

【讨论】:

  • 感谢您的回复!所以如果我想加密一个字符串,我把它分成两个长度相等的部分(xl 和 xr)然后继续? “你好”是加密密钥吗?函数“unsigned long F(unsigned long x)”在哪里使用?再次感谢您的帮助!
  • xl 和 xr 也很长 - 如果我想加密字符串怎么办?谢谢!
  • 建议阅读:http://www.schneier.com/http://www.schneier.com/paper-blowfish-fse.html。请阅读一些文字,让你的思想工作。
猜你喜欢
  • 1970-01-01
  • 2013-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-29
  • 2012-08-23
  • 2012-01-27
相关资源
最近更新 更多