-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 に答える