Skip to main content
gamedev.net
🔒 Locked

Visual Basic Question

Started by ryanb Jul 14, 2004 at 1:42 AM 1 replies 250+ views
Original Post
ryanb
ryanb
Is their a way to password protect and encrypt a file saved by a program written in visual basic. meanning if you try to open the file it askes for a password, suppied when saved, to decrypt the file then dump the info into text boxes?
Ryan B.Forsaken Studioshttp://www.forsaken-studios.net (website comming soon)
alnite
alnite
Of course. You just need to write your own custom file format, language doesn't matter.

The simplest way of doing this would be to insert a boolean variable in a file; if it's true, it means password protected. When you read the file, check if this boolean is true. If so, pops out a dialogbox, ask for a password, then compare it to the password inside the file.
Nice Coder
Nice Coder
First ask for a password,

like,
inp = inputbox("What is the password?")

You then turn int into a number,

i = 1
for x = 1 to len(inp)
i = i * asc(mid(Inp, x, 1))
i = (i mod 256) + 1
next x
i = i - 1

You then open the file for binary as #1 and dump the contents into a byte-buffer

dim bytebuff() as byte
open filename for binary as #1
redim bytebuff(lof(1))
get #1, , bytebuff
close #1

You then decrypt it,

for x = 0 to ubound(bytebuff)
bytebuff(x) = bytebuff(x) xor i
next x

And place it back in the encrypted/decrypted file
open decryptedfilename for binary as #1
put #1, , bytebuff
close #1

and your done!
(WARNING NOT VERY SAFE, KEEP OUT OF REACH OF SMALL CHILDREN)
DENC
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.