home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Working With Binary Data In VB 6.0

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1606
Discussions: 200,951, Posts: 2,379,471, Members: 246,313
Old October 2nd, 2002, 02:15 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Mar 2002
Location: Alberta, Canada
Posts: 11
Send a message via ICQ to SpaceMonkey
Working With Binary Data In VB 6.0

Hey all,

I have a question that may be simple or complex...
here's the deal.

I'm writing a DES encryption program in VB, cause that's the language i am most proficient in, so it's gone the quickest.
Unfortunately, this means that i have to read in a file, and convert it (ASCII->Int->8bitstring) character by character to binary data, using a function i wrote myself.
The program works perfectly, and all the des algorithm code is up to par, but the problem is that with that whole convert to binary, then after decryption, convert from binary, it takes close to 5 min, to encrypt and decrypt a 128kb file... This is an insane amount of time for 128k, so i would like to know, if there's any way to read binary data directly into a string (in it's 100101010 form) so that i don't have to apply my function to each byte, and can just pass that data directly into the encrypt function instead?

I hope this makes some sense, following is some Pseudo code to give you an idea what's going on...

Read In ASCII File

Loop through each character (132,000 characters for the 128k file) one by one and convert first to int using asc() function, then to binary using built function.

Fire that string into the DES Encryption algorithm. (takes a good chunk of time to process as well, because it's just a string of 1's and 0's.)

Receive Binary output from des, and convert back to ascii (giberish after the encryption's run) 8bits at a time...

(running time close to 6 min. give or take.)

If anyone sees where i could cut some time off of that, please let me know, cause i've been over it again and again, and my brain is numb ;)
If all else fails, i will have to switch to C++ and use the bitset datatype, as it seems to have what i need, but i would really rather NOT use c++, does anyone know if there's a similar datatype in VB? I know the byte type, but it only holds one 8bit character, so it doesn't do me any good, when i need to be passing 64 bits through at a time...

Any suggestions/comments are greatly appreciated.

Thanks,
J.
SpaceMonkey is offline   Reply With Quote
Old October 2nd, 2002, 02:43 AM     #2 (permalink)
Senior Member
 
Join Date: Aug 2002
Location: Meeshigan
Posts: 605
Post
Unsigned Numbers = Data

I use Delphi most of the time, so forgive me if this isn't possible in VB. An unsigned number, no matter how many bits, is simply data. You can manipulate it however you want and it remains simply a string of 1s and 0s. When you get a signed number, the sign bit will change depending on the modifications you perform. A byte in Delphi (and other languages too I'd assume) is actually nothing more than an 8 bit unsigned integer.

I'd look at how you're reading the file. It sounds to me like you're reading it as a text file, converting each chunk of data to a binary format, encryting it, then converting it back to ascii and dumping it to disk. The conversion routines are what's probably sucking up most of your CPU time. (I have no idea how your encryption routine is structured though.)
__________________
About 5% of the people in the world can't think.
Another 5% can think and do.
The remaining 90% can think, but don't.
Ruler2112 is offline   Reply With Quote
Old October 2nd, 2002, 04:10 AM     #3 (permalink)
Junior Member
 
Join Date: Mar 2002
Location: Alberta, Canada
Posts: 11
Send a message via ICQ to SpaceMonkey
Yes, a byte in VB is the same (8bit unsigned) but my main problem is i need to physically be able to manipulate specific bits
(ie: move bit 54 to position 1, etc.) as part of the encryption algorithm. I also need to be able to shift the bits to the left or right x number of digets. If i use the "byte" type, i don't have the freedom that i have by putting actual "10010101" code in a string variable and then using the mid() function to select specific bits...

If i am looking at this all wrong, and there is an easier way to maipulate bits, please let me know... It'd make my life MUCH easier!!
But for now, that's the only way i see it being able to happen.

Also, i have set the text file to read in as "binary access", but when i toss it into a string variable, it still comes out as ascii, so i imagine VB is auto-converting the binary code back to ascii as it goes into the string. Any other data types that might not do this?

Let me know what you think,
J.
SpaceMonkey is offline   Reply With Quote
Old October 2nd, 2002, 02:21 PM     #4 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,386
To my knowledge VB does not have the ability to shift bits, or work anything at that low level. VB typically isn't meant to do the kind of work you're asking it to. Wouldnt' an encryption algorithm best be written in a language with more lower level power? C/C++? Maybe even assembly for that matter, especially if it has to do this quickly.
From what I can see in the MSDN For Binary is still designed to pull text from a file, and not binary.
VB isn't really designed to that kind of work
Granted this is to my knowledge, I don't typically work with binary.
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
vass0922 is online now   Reply With Quote
Old October 2nd, 2002, 03:15 PM     #5 (permalink)
Junior Member
 
Join Date: Mar 2002
Location: Alberta, Canada
Posts: 11
Send a message via ICQ to SpaceMonkey
Unfortunately vass, i think you're right.
I've gone over it all again & again, and it seems i won't be able to cut down the times in VB...

Looks like it's C++ for me.

Does anyone know of any good material on using the BITSET type in C++? I've looked, and found lot of info on how the header is structured, but not many practical examples to go through and see it in action.
SpaceMonkey is offline   Reply With Quote
Old October 2nd, 2002, 03:29 PM     #6 (permalink)
Senior Member
 
Join Date: Aug 2002
Location: Meeshigan
Posts: 605
If you use Delphi, you have the shl and shr routines, the same as they are in assembler. Shifts the bits one position left or one position right, respectively. I've done some binary manipulation routines in Delphi and it handles it well. Has the power of C++, but isn't so freaking obscure syntactically.

Yeah, VB is converting the binary form to ASCII; I'd say this is where the majority of your slowdown is coming from. I don't know enough about the internal workings of VB to advise you how to get around this problem, or if it's even possible in the language. VB was never meant for this type of work; more for developing GUIs and basic (no pun intended ) business apps.
Ruler2112 is offline   Reply With Quote
Old October 3rd, 2002, 12:20 AM     #7 (permalink)
Member
 
Join Date: Oct 2001
Location: Houston, BY GOD, Texas
Posts: 98
There is a set of controls, FastLib.net that contains a Math Object. If I remember correctly it has the ability to do binary math. Check it out.

http://www.fastlib.net
DocHopper is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
The disrespect of Obama by Russian .. (39)
Is It Just Me? (2942)
Making Health Care Worse (178)
Wireless Televisions. (12)
CPU fan stops spinning randomly (8)
windows 7 problem (7)
Regular Build (11)
Is the PSU I received dead? (12)
radeon x850xt platinum & shader.. (6)
Print spooler problem (15)
windows vista security holes (10)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Foreign voltage (10)
Recent Discussions
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Modern Warfare 2: Who Bought It? (63)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Laptop with wireless problem. (3)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
windows vista security holes (10)
Point and Shoot Camera Suggestions. (4)
Multiple Restarts Required at Boot (2)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Hp Artist Edition + Matching Bag (0)
Asus P4G8X Mobo (6)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)


All times are GMT -4. The time now is 01:40 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28