Re: Looking for a simple blowfish example



d-fan wrote:
On May 14, 3:44 am, Randy Thompson <RThomp...@xxxxxxxxxxxxx> wrote:
d-fan wrote:
On May 9, 8:02 am, Randy Thompson <RThomp...@xxxxxxxxxxxxx> wrote:
d-fan wrote:
Can someone point me to a simple example of "C" programming using
Blowfishto encrypt and decrypt? I am a newbie to the world of
encryption and I could really use an example if how to encrypt a
string of text consisting of approximately 16 characters and
decrypting them usingblowfish. I am using a Linux platform as my
development platform.
There is a link from here:http://www.schneier.com/blowfish.html
called "Free source code available". The one by Paul Kocher is fairly
easy to understand.
You may also find something from here that you like:ftp://ftp.zedz.net/pub/crypto/libraries/blowfish/
I did read and use the sample program by Paul Kocher. I am trying to
understant the parameters that are passed. I can see how the key is
setup, but i can't understant the left and right concept. I simply
want to encrypt something like "HAPPY Dog" and be able to decrypt
it. How does a word or phrase like this get passed a a parameter to
the encrypt and decrypt routine.
Below is the blowfish_test.c file rewritten with "HAPPYDog" as the
plaintext.
I excluded the space to make it 8 bytes long, or 1 block inBlowfish.
"HAPPYDog" in ASCII hexadecimal is "4841505059446F67"
so L will be 0x48415050L, and R will be 0x59446F67L.

(Note: You may want to reverse those values to conform to the
little-endian format.
i.e. L = 0x50504148L and R = 0x676F4459L. And also reverse the
output from the
Blowfish_Decrypt function. But that's not necessary here.)

/*
blowfish_test.c: Test file forblowfish.c

Copyright (C) 1997 by Paul Kocher

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <stdio.h>
#include "blowfish.h"

int main(void) {
unsigned long L = 0x48415050L, R = 0x59446F67L; /* HAPPYDog */
BLOWFISH_CTX ctx;

Blowfish_Init (&ctx, (unsigned char*)"TESTKEY", 7);
Blowfish_Encrypt(&ctx, &L, &R);
printf("%08lX %08lX\n", L, R);
if (L == 0xF570C2B1L && R == 0xB8A3A68BL)
printf("Test encryption OK.\n");
else
printf("Test encryption failed.\n");
Blowfish_Decrypt(&ctx, &L, &R);
printf("%08lX %08lX\n", L, R);
if (L == 0x48415050L && R == 0x59446F67L)
printf("Test decryption OK.\n");
else
printf("Test decryption failed.\n");
return 0;

}

HTH,
Randy- Hide quoted text -

- Show quoted text -

Thanks so much for your informative reply. I do have a few remaining
questions. What happend is the text was shorter or longet such as
"HAPPYd" or "HAPPYDogandCat"?

Usually if there are fewer bytes than the block size, you would add extra
bytes to make it equal to the size of the block. For instance, "HAPPYd ".
I just added two extra spaces to the end.

For "HAPPYDogandCat", you end up with 2 blocks. The first one, "HAPPYDog",
is 8 bytes, and the second one, "andCat ", has 2 spaces add to the end to make
it also 8 bytes long.

Most of the time, a zero byte (0x00) is used as padding to fill up blocks. I used a
space here for convenience.

How interchangeble are the various versions of blowfish.

As far as I know, they all should be interchangeable.

Can I send my encrypted data to a windows box and decrypt it?

You most certainly can. I'm not sure how you would do that in Linux.

What is the best way to convert text to Hex in "C"?

There are several conversion routines in C to be found on the Internet.
This is where you get to learn to use almighty Google.
Or, you can write your own. You're not restricted to using what's already
written.

Best of luck,
Randy




.



Relevant Pages

  • Re: Looking for a simple blowfish example
    ... Blowfishto encrypt and decrypt? ... version 2.1 of the License, or any later version. ... a string or character text instead of an integer expecially a 1 and a ...
    (sci.crypt)
  • RE: NTE_BAD_DATA
    ... They are NOT used DIRECTLY to encrypt / decrypt data; ... you should generate a RANDOM SESSION KEY and select a SYMMETRIC ENCRYPTION ... // imported from a BLOB read in from the source file or having ...
    (microsoft.public.platformsdk.security)
  • Re: Looking for a simple blowfish example
    ... Blowfishto encrypt and decrypt? ... version 2.1 of the License, or any later version. ... a string or character text instead of an integer expecially a 1 and a ...
    (sci.crypt)
  • Re: encrypting licenses
    ... do the decryption at runtime from the supplied license file? ... I like to encrypt the license file in one application and decrypt it ... Use a private key-pair to encrypt and an public one to decrypt. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Looking for a simple blowfish example
    ... Blowfishto encrypt and decrypt? ... This library is free software; ... version 2.1 of the License, or any later version. ...
    (sci.crypt)