Main Page | Report this Page
 
   
Science Forum Index  »  Cryptography Forum  »  Looking for a simple blowfish example...
Page 1 of 1    
Author Message
d-fan...
Posted: Thu May 08, 2008 9:26 pm
Guest
Can someone point me to a simple example of "C" programming using
Blowfish to 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 using blowfish. I am using a Linux platform as my
development platform.
d-fan...
Posted: Fri May 09, 2008 7:36 am
Guest
On May 9, 9:23 am, rossum <rossu... at (no spam) coldmail.com> wrote:
Quote:
On Fri, 9 May 2008 00:26:55 -0700 (PDT), d-fan

rafel.co... at (no spam) pfshouston.com> wrote:
Can someone point me to a simple example of "C" programming using
Blowfish to 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 using blowfish.  I am using a Linux platform as my
development platform.

Have a lookhttp://libtom.org/This has C code including Blowfish.

rossum

Thanks for your reply. Is there a way to see a cleaner implementation
of blowfish alone? Do you have to create the big arrays? As a newbie
I can't separate the blowfish from the other encryption examples. I
just need to find the minimum coding required to implement blowfish on
linux.
Randy Thompson...
Posted: Fri May 09, 2008 8:02 am
Guest
d-fan wrote:
Quote:
Can someone point me to a simple example of "C" programming using
Blowfish to 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 using blowfish. 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/
rossum...
Posted: Fri May 09, 2008 9:23 am
Guest
On Fri, 9 May 2008 00:26:55 -0700 (PDT), d-fan
<rafel.coyle at (no spam) pfshouston.com> wrote:

Quote:
Can someone point me to a simple example of "C" programming using
Blowfish to 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 using blowfish. I am using a Linux platform as my
development platform.
Have a look http://libtom.org/ This has C code including Blowfish.


rossum
rossum...
Posted: Fri May 09, 2008 2:15 pm
Guest
On Fri, 9 May 2008 10:36:14 -0700 (PDT), d-fan
<rafel.coyle at (no spam) pfshouston.com> wrote:

Quote:
On May 9, 9:23 am, rossum <rossu... at (no spam) coldmail.com> wrote:
On Fri, 9 May 2008 00:26:55 -0700 (PDT), d-fan

rafel.co... at (no spam) pfshouston.com> wrote:
Can someone point me to a simple example of "C" programming using
Blowfish to 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 using blowfish.  I am using a Linux platform as my
development platform.

Have a lookhttp://libtom.org/This has C code including Blowfish.

rossum

Thanks for your reply. Is there a way to see a cleaner implementation
of blowfish alone? Do you have to create the big arrays? As a newbie
I can't separate the blowfish from the other encryption examples. I
just need to find the minimum coding required to implement blowfish on
linux.
If you want just Blowfish then either follow Randy's suggestions or

follow the links from the Wikipedia page:
http://en.wikipedia.org/wiki/Blowfish_(cipher)

rossum
Randy Thompson...
Posted: Wed May 14, 2008 3:44 am
Guest
d-fan wrote:
Quote:
On May 9, 8:02 am, Randy Thompson <RThomp... at (no spam) mirratone.net> 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 in Blowfish.
"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 for blowfish.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
d-fan...
Posted: Wed May 14, 2008 4:54 am
Guest
On May 14, 3:44 am, Randy Thompson <RThomp... at (no spam) mirratone.net> wrote:
Quote:
d-fan wrote:
On May 9, 8:02 am, Randy Thompson <RThomp... at (no spam) mirratone.net> 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"? How interchangeble are the various
versions of blowfish. Can I send my encrypted data to a windows box
and decrypt it? What is the best way to convert text to Hex in "C"?
d-fan...
Posted: Thu May 15, 2008 2:42 am
Guest
On May 15, 3:37 am, Randy Thompson <RThomp... at (no spam) mirratone.net> wrote:
Quote:
d-fan wrote:
On May 14, 3:44 am, Randy Thompson <RThomp... at (no spam) mirratone.net> wrote:
d-fan wrote:
On May 9, 8:02 am, Randy Thompson <RThomp... at (no spam) mirratone.net> 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 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.
Randy Thompson...
Posted: Thu May 15, 2008 3:37 am
Guest
d-fan wrote:
Quote:
On May 14, 3:44 am, Randy Thompson <RThomp... at (no spam) mirratone.net> wrote:
d-fan wrote:
On May 9, 8:02 am, Randy Thompson <RThomp... at (no spam) mirratone.net> 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.

Quote:
How interchangeble are the various versions of blowfish.

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

Quote:
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.

Quote:
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
d-fan...
Posted: Thu May 15, 2008 4:20 am
Guest
On May 15, 7:42 am, d-fan <rafel.co... at (no spam) pfshouston.com> wrote:
Quote:
On May 15, 3:37 am, Randy Thompson <RThomp... at (no spam) mirratone.net> wrote:





d-fan wrote:
On May 14, 3:44 am, Randy Thompson <RThomp... at (no spam) mirratone.net> wrote:
d-fan wrote:
On May 9, 8:02 am, Randy Thompson <RThomp... at (no spam) mirratone.net> 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 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.- Hide quoted text -

- Show quoted text
I wish that the original example had been creating using char arrays

instead of integers. That would have been much more valuable.
Randy Thompson...
Posted: Thu May 15, 2008 6:14 pm
Guest
d-fan wrote:

Quote:
I wish that the original example had been creating using char arrays
instead of integers. That would have been much more valuable.



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


int main(void) {

BLOWFISH_CTX ctx;

unsigned long L, R;
unsigned char inpbuf[9];

strcpy(inpbuf, "HAPPYDog");

L = 0;
R = 0;

L += (inpbuf[0] * 0x01000000L);
L += (inpbuf[1] * 0x00010000L);
L += (inpbuf[2] * 0x00000100L);
L += (inpbuf[3]);
R += (inpbuf[4] * 0x01000000L);
R += (inpbuf[5] * 0x00010000L);
R += (inpbuf[6] * 0x00000100L);
R += (inpbuf[7]);

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;
}
d-fan...
Posted: Thu May 15, 2008 8:06 pm
Guest
On May 15, 6:14 pm, Randy Thompson <RThomp... at (no spam) mirratone.net> wrote:
Quote:
d-fan wrote:
I wish that the original example had been creating using char arrays
instead of integers.  That would have been much more valuable.

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

int main(void) {

   BLOWFISH_CTX ctx;

   unsigned long L, R;
   unsigned char inpbuf[9];

   strcpy(inpbuf, "HAPPYDog");

   L = 0;
   R = 0;

   L += (inpbuf[0] * 0x01000000L);
   L += (inpbuf[1] * 0x00010000L);
   L += (inpbuf[2] * 0x00000100L);
   L += (inpbuf[3]);
   R += (inpbuf[4] * 0x01000000L);
   R += (inpbuf[5] * 0x00010000L);
   R += (inpbuf[6] * 0x00000100L);
   R += (inpbuf[7]);

   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;



}- Hide quoted text -

- Show quoted text -

Thanks again for the help. I am down to my final piece where I need
to write the encrypted values to a text file. I know how to write a
unsigned char 8 string to a file, but I can't cat the values to the
string pointer. Do I have to do this two characters at a time?
Randy Thompson...
Posted: Sat May 17, 2008 4:05 am
Guest
d-fan wrote:

Quote:

Thanks again for the help. I am down to my final piece where I need
to write the encrypted values to a text file. I know how to write a
unsigned char 8 string to a file, but I can't cat the values to the
string pointer. Do I have to do this two characters at a time?

I think this is what you're looking for in blowfish_test.c:

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

int main(void) {

BLOWFISH_CTX ctx;

int i, j;
unsigned long L, R;
char str[9];
char hexbuf[17];
unsigned char inpbuf[9];
unsigned char outbuf[17];

strcpy(inpbuf, "HAPPYDog");

L = 0;
R = 0;

L += (inpbuf[0] * 0x01000000L);
L += (inpbuf[1] * 0x00010000L);
L += (inpbuf[2] * 0x00000100L);
L += (inpbuf[3]);
R += (inpbuf[4] * 0x01000000L);
R += (inpbuf[5] * 0x00010000L);
R += (inpbuf[6] * 0x00000100L);
R += (inpbuf[7]);

Blowfish_Init (&ctx, (unsigned char*)"TESTKEY", 7);
Blowfish_Encrypt(&ctx, &L, &R);
printf("%s\n", inpbuf);
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);

str[0] = 0;
hexbuf[0] = 0;

sprintf(str, "%08lX", L);
strcat(hexbuf, str);

str[0] = 0;
sprintf(str, "%08lX", R);
strcat(hexbuf, str);

strncpy(outbuf, hexbuf, 16);
for (i = 0; i < 8; i++) {
sscanf(&hexbuf[i * 2], "%02X", &j);
outbuf[i] = (char)j;
}
outbuf[8] = 0;

printf("%08lX %08lX\n", L, R);
printf("%s\n", outbuf);

if (L == 0x48415050L && R == 0x59446F67L)
printf("Test decryption OK.\n");
else
printf("Test decryption failed.\n");
return 0;
}
d-fan...
Posted: Sun May 18, 2008 8:01 pm
Guest
On May 17, 4:05 am, Randy Thompson <RThomp... at (no spam) mirratone.net> wrote:
Quote:
d-fan wrote:

Thanks again for the help.  I am down to my final piece where I need
to write the encrypted values to a text file.  I know how to write a
unsigned char 8 string to a file, but I can't cat the values to the
string pointer.  Do I have to do this two characters at a time?

I think this is what you're looking for in blowfish_test.c:

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

int main(void) {

   BLOWFISH_CTX ctx;

   int i, j;
   unsigned long L, R;
   char str[9];
   char hexbuf[17];
   unsigned char inpbuf[9];
   unsigned char outbuf[17];

   strcpy(inpbuf, "HAPPYDog");

   L = 0;
   R = 0;

   L += (inpbuf[0] * 0x01000000L);
   L += (inpbuf[1] * 0x00010000L);
   L += (inpbuf[2] * 0x00000100L);
   L += (inpbuf[3]);
   R += (inpbuf[4] * 0x01000000L);
   R += (inpbuf[5] * 0x00010000L);
   R += (inpbuf[6] * 0x00000100L);
   R += (inpbuf[7]);

   Blowfish_Init (&ctx, (unsigned char*)"TESTKEY", 7);
   Blowfish_Encrypt(&ctx, &L, &R);
   printf("%s\n", inpbuf);
   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);

   str[0] = 0;
   hexbuf[0] = 0;

   sprintf(str, "%08lX", L);
   strcat(hexbuf, str);

   str[0] = 0;
   sprintf(str, "%08lX", R);
   strcat(hexbuf, str);

   strncpy(outbuf, hexbuf, 16);
   for (i = 0; i < 8; i++) {
     sscanf(&hexbuf[i * 2], "%02X", &j);
     outbuf[i] = (char)j;
   }
   outbuf[8] = 0;

   printf("%08lX %08lX\n", L, R);
   printf("%s\n", outbuf);

I guess that at this point the output buffer contains the data that I

need to write to a file.
Quote:
   if (L == 0x48415050L && R == 0x59446F67L)
          printf("Test decryption OK.\n");
   else
          printf("Test decryption failed.\n");
return 0;



}- Hide quoted text -

- Show quoted text -

This has been my overall goal.

I need to be able to read data such as a credit car number, etc.
either from a external text file or passed in as a parameter.
The data has to be encrypted, base64 encoded and then either stored in
a file or passed back as a parameter. Also, we must be able to the
reverse of this process. That is we must be able to read data, base64
decode, decrypt, and return the data as a parameter or store it into a
file. This is my overall go in using Blowfish and it has been most
difficult from the examplees that I have seen. Is my use of the
encryption and ecode/decode impractical here?
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Sat Jul 26, 2008 5:15 pm