Re: Looking for a simple blowfish example
- From: d-fan <rafel.coyle@xxxxxxxxxxxxxx>
- Date: Thu, 15 May 2008 05:42:17 -0700 (PDT)
On May 15, 3:37 am, Randy Thompson <RThomp...@xxxxxxxxxxxxx> wrote:
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:Below is the blowfish_test.c file rewritten with "HAPPYDog" as the
d-fan wrote:I did read and use the sample program by Paul Kocher. I am trying to
Can someone point me to a simple example of "C" programming usingThere is a link from here:http://www.schneier.com/blowfish.html
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.
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/
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.
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 ofblowfish.
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- Hide quoted text -
- Show quoted text -
Thanks for your help. I wish that the example would have demonstrated
a string or character text instead of an integer expecially a 1 and a
2. It make it seem like the 2 is a size reference instead of just the
right half of the number.
Trying to find conversion routines in Google is worse that a needle in
a haystack. There is usually a finite amount of hay.
.
- Follow-Ups:
- Re: Looking for a simple blowfish example
- From: d-fan
- Re: Looking for a simple blowfish example
- References:
- Looking for a simple blowfish example
- From: d-fan
- Re: Looking for a simple blowfish example
- From: Randy Thompson
- Re: Looking for a simple blowfish example
- From: d-fan
- Re: Looking for a simple blowfish example
- From: Randy Thompson
- Re: Looking for a simple blowfish example
- From: d-fan
- Re: Looking for a simple blowfish example
- From: Randy Thompson
- Looking for a simple blowfish example
- Prev by Date: The Wisdom in Islam
- Next by Date: New underwater, trip and models photogallery
- Previous by thread: Re: Looking for a simple blowfish example
- Next by thread: Re: Looking for a simple blowfish example
- Index(es):
Relevant Pages
|
|