Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 30th, 2004, 12:07 PM
CCDemonX's Avatar
CCDemonX CCDemonX is offline
WebDeveloper++;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: New York City
Posts: 85 CCDemonX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Blowfish problems

Hey, I have a problem. I have two Blowfish classes: one in Python, and one in Java. Now, when I try to encrypt the following:

key: [102, 111, 111, 108, 98, 97, 114, 122]
data: [116, 101, 115, 116, 116, 101, 115, 116]

In python I get a result of: [18, 196, 31, 187, 245, 170, 192, 170]

In java I get a result of: [-50, 62, -123, 18, 42, 2, -72, -59] which translates to: [206, 62, 133, 18, 42, 2, 184, 197]

Now, what I wonder is... what factors cause the two classes to get different results?? They are both blowfish classes, and have the same p boxes and s boxes. When I try to decrypt the results using the key again, I get the original data, so they do work fine. What could be the problem? I'm very new to blowfish.

I'm trying to port a program from Java to Python, so its important I get the same result I get in Java for my Python program to work.

Reply With Quote
  #2  
Old June 30th, 2004, 12:54 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 11
Send a message via MSN to Grim Archon
Which one do you consider gives the correct encryption and at which point in your code does the other version start to go wrong?
__________________
*** Experimental Python Markup CGI V2 ***

Last edited by Grim Archon : June 30th, 2004 at 12:57 PM.

Reply With Quote
  #3  
Old June 30th, 2004, 01:07 PM
Noah_C Noah_C is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 37 Noah_C User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 24 sec
Reputation Power: 8
I'm sorry I don't have the ansewers for you. I checked out the Blowfish FAQ to see if I could come up with something, but I'd like to see if I'm understand you right....

key: [102, 111, 111, 108, 98, 97, 114, 122] -- Key for Both
data: [116, 101, 115, 116, 116, 101, 115, 116] -- Plaindata
[18, 196, 31, 187, 245, 170, 192, 170] -- encrypted on Python
[206, 62, 133, 18, 42, 2, 184, 197] -- encrypted on Java

So do they decrypt alright ? If so then what is the big deal? Unless you're trying to get your python program to pass the encrypted data to another program that the java program did.

Reply With Quote
  #4  
Old June 30th, 2004, 01:20 PM
CCDemonX's Avatar
CCDemonX CCDemonX is offline
WebDeveloper++;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: New York City
Posts: 85 CCDemonX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Quote:
Originally Posted by Grim Archon
Which one do you consider gives the correct encryption and at which point in your code does the other version start to go wrong?


The Java version is the output I am looking for. The python version gives a completely different output. I'm trying to build a program that decrypts a file from the filesystem. It's important that python gets the same result as the java version or it won't be able to decrypt it to its plaintext.

Quote:
Originally Posted by Noah_C
I'm sorry I don't have the ansewers for you. I checked out the Blowfish FAQ to see if I could come up with something, but I'd like to see if I'm understand you right....

key: [102, 111, 111, 108, 98, 97, 114, 122] -- Key for Both
data: [116, 101, 115, 116, 116, 101, 115, 116] -- Plaindata
[18, 196, 31, 187, 245, 170, 192, 170] -- encrypted on Python
[206, 62, 133, 18, 42, 2, 184, 197] -- encrypted on Java

So do they decrypt alright ? If so then what is the big deal? Unless you're trying to get your python program to pass the encrypted data to another program that the java program did.


Yes, they decrypt alright if encrypted from the same class, but its imporant that the code is portable. Like I said above, the python program needs to be able to open a file that was already encrypted with an output similar to the java program.

I still don't know what could cause this. Isn't the output suppose to be the same regardless of the class as long as its blowfish?

Reply With Quote
  #5  
Old June 30th, 2004, 02:06 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 8,978 Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 6 Days 22 h 14 m 39 sec
Reputation Power: 3561
Maybe one is enciphering in Electronic Code Book Mode (ECB) and the other is enciphering in Cipherblock Chaining (CBC) mode?
http://www.openbsd.org/cgi-bin/man....386&format=html

I whipped up some C code that does the encryption in ECB mode. The output is identical to your python code.
Code:
#include <stdio.h>
#include <blf.h>

int main(void)
{
  u_int8_t key[] = {102, 111, 111, 108, 98, 97, 114, 122};
  u_int8_t data[] = {116, 101, 115, 116, 116, 101, 115, 116};
  blf_ctx state;
  int i;

  blf_key(&state, key, sizeof(key));
  blf_ecb_encrypt(&state, data, sizeof(data));

  for (i = 0; i < sizeof(data); i++)
    printf("%d\n", (unsigned int) data[i]);

  return 0;
}
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Diary of a first time dog owner <-- my cousin's blog

Reply With Quote
  #6  
Old June 30th, 2004, 03:40 PM
CCDemonX's Avatar
CCDemonX CCDemonX is offline
WebDeveloper++;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: New York City
Posts: 85 CCDemonX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Yes. In the Python version, I am using ECB mode. However, I don't know what mode the Java version uses. I tried every single mode available in the Crypto.Cipher.Blowfish module except CTR and I still don't get the same outout:

Code:
Mode #1 (ECB)
        key: [102, 111, 111, 108, 98, 97, 114, 122]
        before: [116, 101, 115, 116, 116, 101, 115, 116]
        after: [18, 196, 31, 187, 245, 170, 192, 170]
Mode #2 (CBC)
        key: [102, 111, 111, 108, 98, 97, 114, 122]
        before: [116, 101, 115, 116, 116, 101, 115, 116]
        after: [18, 196, 31, 187, 245, 170, 192, 170]
Mode #3 (CFB)
        key: [102, 111, 111, 108, 98, 97, 114, 122]
        before: [116, 101, 115, 116, 116, 101, 115, 116]
        after: [76, 148, 247, 187, 72, 120, 27, 140]
Mode #4 (PGP)
        key: [102, 111, 111, 108, 98, 97, 114, 122]
        before: [116, 101, 115, 116, 116, 101, 115, 116]
        after: [76, 113, 104, 158, 33, 198, 91, 112]
Mode #5 (OFB) 
        key: [102, 111, 111, 108, 98, 97, 114, 122]
        before: [116, 101, 115, 116, 116, 101, 115, 116]
        after: [76, 113, 104, 158, 33, 198, 91, 112]


Below is the Java file with the BlowfishEngine class. Any idea what mode this might be?

http://www.raineri.ws/code/BlowfishEngine.java

Reply With Quote
  #7  
Old June 30th, 2004, 03:48 PM
obi_wonton's Avatar
obi_wonton obi_wonton is offline
(not) Banned
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2004
Location: Toronto, CANADA
Posts: 598 obi_wonton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 4 m 13 sec
Reputation Power: 8
Are the variables that you are using the same type as in the python script? I'm not sure if that would make a difference, but hey, there's my two cents.

Reply With Quote
  #8  
Old June 30th, 2004, 04:25 PM
CCDemonX's Avatar
CCDemonX CCDemonX is offline
WebDeveloper++;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: New York City
Posts: 85 CCDemonX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Quote:
Originally Posted by obi_wonton
Are the variables that you are using the same type as in the python script? I'm not sure if that would make a difference, but hey, there's my two cents.


They both get transformed from string into an array/list.

Reply With Quote
  #9  
Old June 30th, 2004, 06:52 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 8,978 Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 39th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 6 Days 22 h 14 m 39 sec
Reputation Power: 3561
How about trying a different API instead, for instance one from Sun.
http://java.sun.com/products/jce/do...sers_guide.html

Right now, we know that the python and C API coincide. Matter of fact, I got the same output with the C program and CBC mode (initial array was set to 0)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Blowfish problems


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap