|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Password for DBF
--
Dear Friend:
Perhaps I didn't understand the message very well, but if you want to protect the DBF file from being opened by another application, here is a little trick you can use.
DBF files, like the other ones, have a header at the very beggining of the file, This header contains very important information that allows application to determine how many records are inserted, what fields are in the table, and type information for each one of them.
What you cant do is encrypt the file's header (the first 2048 bytes of the file) with the XOR Function. Here's the Algorithm:
Function Encrypt(TextToEncript As String) as String
Dim CountofChar as Integer 'Counter for iteration
Dim CountOfEncr as Integer 'Counter for iteration on key
'Because sometimes you need to
'encrypt lager text than the key
'is itself.
Dim EncrypString$ 'String that contains the key (pwd)
Dim CharOriginal$ 'Char extracted from the orig text.
Dim CharEncripte$ 'Char containing the encripted result
Dim DestinString$ 'Destination encrypted string
'This is the key that you can use to encrypt the text
'You have to keep it constant to deencrypt the text again
EncrypString$ = "THIS IS THE PASSWORD"
'Begin iteration to encrypt each char of the string until
'It finishes
CountOfEncr = 1
For CountOfChar = 1 To Len(TextToEncript)
'Extract The corresponding Char from the original string
CharOriginal$(TextToEncript, CountOfChar, 1)
'Extract The corresponding Char from the Encriptor string
CharEncripte$(EncrypString$, CountOfEncr, 1)
'Now that we have both chars, we are going to XOR them to
'Obtain the corresponding encrypted char for that position.
CharEncripte$ = Chr$(ASC(CharOriginal$) XOR ASC(CharOriginal$))
'And finally, we concat that char to the dest encrypted string
DestinString$ = DestinString$ + CharEncripte$
'Now, we need to increment mannualy the counter of the next
'character for the enncryption key. We also need to check if
'the end of the key has been reached.
If CountofEncr = Len(EncryptString$) Then
CountOfEncr = 1
Else
CountOfEncr = CountOfEncr +1
End If
Next CountOfChar
Encrypt = DestinString$
End Function
Well, that's all about the algorithm, now let's see what it does. Supose that you have a char that you want to encrypt, an "A" for example. And your password is a "B" then XOR does do following:
Binary Code for "A" 01000001 (65 Dec.)
Binary Code for "B" 01000010 (66 Dec.)
XOR Opperation --------
XOR RESULT --------->00000011 A TOTALLY DIFFERENT CHAR CODE THAN
THE ORIGINAL "A"
Now, here comes the deencryption part. To do this you just simply use another XOR on the encrypted char. using the same key:
Encrypted Char 03 00000011
Bynare code for "B" 01000010
XOR Opperation --------
XOR Result --------->01000001 "A" Now we have the original char
again.
So, the algorithm above, does this, but with strings. Perhaps you might consider this a little bit simple, but if you hold the key as a constant in your code, it will be hard to decipher, since once you compiled the code, no one will be able to see the key.
I hope this humble idea helps!
Moisis Franco
Join 18 million Eudora users by signing up for a free Eudora Web-Mail account at http://www.eudoramail.com
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once
To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html
|
|