Schneier's Blowfish [closed]
-
28-10-2019 - |
Question
Can someone please show me an example usage of Schneier's Blowfish code (http://www.schneier.com/code/bfsh-sch.zip), i.e. encrypting and decrypting a string with a given key, in C or C++?
Thanks in advance.
Edit: this is not a homework assignment.
Solution
Here is a test
#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;
}
Please make sure the header file name's character case. Also note the file name blowfish.dat
is correct.
Also have a look at Paul Kocher's Implementation from this page : http://www.schneier.com/blowfish-download.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow