|
-
Oct 11th, 2000, 01:12 PM
#1
Thread Starter
Frenzied Member
Hi,
I have a 2MB text file that I need to be able to encrypt/decrypt quickly so the user does not have to wait too long..
The idea is to just keep the casual user from looking at the text file directly.. If a hacker can crack the code, then oh well.. No biggy.. My priority is speed and then encryption..
As an alternative, is it possible to compile a text file within the executable? The text will not ever change.. Probably not, but I just thought I'd ask..
I used the CryptoAPI module found at freevbcode.com but it took so long it locked up my computer..
When replying, please keep in mind that I'm new to this subject so I need example code to go along with your suggestions..
Thanks,
Dan
-
Oct 11th, 2000, 02:04 PM
#2
_______
<?>
Code:
'Encrypt/Unencrypt a file
'
Option Explicit
'
Private Function EncryptFile(sFile As String, iKey As Integer)
Dim iFake#
Dim x As String * 1
Dim lP As Long, z
Dim intNum#
intNum = FreeFile
iFake = Rnd(-1)
Randomize (iKey)
lP = 1
Open sFile For Binary As intNum
While lP <= LOF(intNum)
Get #intNum, lP, x
z = Asc(x) + Int(Rnd * 256)
If z > 255 Then z = z - 256
x = Chr(z)
Put #intNum, lP, x
lP = lP + 1
Wend
Close #intNum
MsgBox "Your file has been encrypted."
End Function
Private Function DecryptFile(sFile As String, iKey As Integer)
Dim iFake As Integer
Dim x As String * 1
Dim lP As Long, z
Dim intNum#
intNum = FreeFile
iFake = Rnd(-1)
Randomize (iKey)
lP = 1
Open sFile For Binary As #intNum
While lP <= LOF(intNum)
Get #intNum, lP, x
z = Asc(x) - Int(Rnd * 256)
If z < 0 Then z = z + 256
x = Chr(z)
Put #intNum, lP, x
lP = lP + 1
Wend
Close #intNum
MsgBox "Your file has been unencrypted."
End Function
' <<<< Form Event Code >>>>
Private Sub Command1_Click()
'encrypt the file
Call EncryptFile("C:\myFile.txt", 44)
End Sub
Private Sub Command2_Click()
'decrypt the file
Call DecryptFile("c:\myFile.txt", 44)
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 16th, 2000, 04:38 PM
#3
Thread Starter
Frenzied Member
Thanks! works great..
Now, how would I modify it to just decrypt it into memory into a string variable while leaving the actual file encrypted?
Thanks,
Dan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|