ianpaisley
Nov 22nd, 1999, 08:21 AM
Aaron,
I'm curious to know what you mean by 'Very Simple'? Do you mean any gobdah at all, with little knowledge of VB, could decrypt the file? How? By trial and error? Or would it take a considerably experienced hacker to do it? Just curious.....
Thanks!
davidck
Nov 22nd, 1999, 11:34 AM
I am building an application that will transfer files over the internet. I want to be able to secure these files by encrypting them or locking them so that no one can see or use them at least I want to try and do that. Does anyone have any suggestions?
Aaron Young
Nov 22nd, 1999, 11:46 AM
All you really need to do is jumble the contents of the file around in such a way that you know how to unjumble it at the other end, eg. You could switch pairs of bytes before transfer, then switch them back after.
How complex and secure the encryption is depends on the method you use.
Here's an example of a Very Simple method of Encryption, which generates a Key to Encrypt and Decrypt a Text File.
Private Sub Command1_Click()
'Open Encrypted File
Dim sText As String
Dim iFile As Integer
On Error GoTo Cancelled
With CommonDialog1
.CancelError = True
.Filter = "AY Encrypted|*.aye"
.ShowOpen
iFile = FreeFile
Open .FileName For Input As iFile
sText = Input(LOF(iFile), iFile)
Close iFile
End With
If Left(sText, 12) <> "AY Encrypted" Then
MsgBox "Not an AY Encrypted File Format"
Else
Text1 = DecryptText(sText)
End If
Cancelled:
End Sub
Private Sub Command2_Click()
'Save Encrypted File
On Error GoTo Cancelled
With CommonDialog1
.CancelError = True
.Filter = "AY Encrypted|*.aye"
.ShowSave
iFile = FreeFile
Open .FileName For Output As iFile
Print #iFile, EncryptText(Text1);
Close iFile
End With
MsgBox "Saved"
Cancelled:
End Sub
Function EncryptText(ByVal sText As String) As String
Dim sKey As String
Dim iKey As Integer
Dim lPos As Long
Dim iChar As Integer
Dim iEx As Integer
Randomize Timer
sKey = Right("000" & Hex(Int(Rnd(1) * 4095)), 3)
For lPos = 1 To Len(sText)
iChar = Asc(Mid$(sText, lPos, 1))
iEx = iChar + Val("&H" & Mid(sKey, iKey + 1, 1))
Mid$(sText, lPos, 1) = Chr(iEx)
iKey = (iKey + 1) Mod 3
Next
EncryptText = "AY Encrypted" & sText & Right(Space(20) & (Val("&H" & sKey) + Len(sText)), 20)
End Function
Function DecryptText(ByVal sText As String) As String
Dim sKey As String
Dim iKey As Integer
Dim lPos As Long
Dim iChar As Integer
Dim iEx As Integer
sText = Mid(sText, 13)
sKey = Right("000" & Hex(Val(Right(sText, 20)) - (Len(sText) - 20)), 3)
For lPos = 1 To Len(sText) - 20
iChar = Asc(Mid$(sText, lPos, 1))
iEx = iChar - Val("&H" & Mid(sKey, iKey + 1, 1))
Mid$(sText, lPos, 1) = Chr(iEx)
iKey = (iKey + 1) Mod 3
Next
DecryptText = Left(sText, Len(sText) - 20)
End Function
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net