|
Public Function EncDecString(strSource As String, _
Optional strKey As String = "jhGd&34") As String Dim i As Integer Dim intAscSource As Integer Dim strTempEncDec As String Dim strSeed As String Dim intkey As Integer 'generates Seed for the randomize event 'through Ascii codes of each of the characters of the key For i = 1 To Len(strKey) strSeed = strSeed & Asc(Mid(strKey, i, 1)) Next i Rnd -1 'Because i want to work With the same random table Randomize CDbl(strSeed) For i = 1 To Len(strSource) intkey = Int(256 * Rnd) 'generates an Integer (0-255) intAscSource = Asc(Mid(strSource, i, 1)) strTempEncDec = strTempEncDec & _ Chr(intAscSource Xor intkey) 'The actual encryption takes place here Next i EncDecString = strTempEncDec End Function Public Sub EncDecFile(strSource As String, _ Optional bolShowProgress As Boolean = False, _ Optional objProgress As ProgressBar) Dim iFile As Integer Dim StrStream As String * 100 Dim lngSteps As Long Dim i As Long iFile = FreeFile() Open strSource For Binary As iFile 'Help me on this one, please. 'How can i avoid this and work on the entire file? 'I had difficulty trying to deal with the Seek statement. 'If you notice, i'm working on 100 bytes 'segments and discarding the last <=99 bytes. lngSteps = Int(LOF(iFile) / 100) 'inicializes the progress bar. If bolShowProgress Then objProgress.Min = 0 objProgress.Max = lngSteps objProgress.Value = 0 End If For i = 1 To lngSteps Get iFile, i, StrStream StrStream = EncDecString(StrStream) 'calls the Function above where the encryption 'takes place. Put iFile, i, StrStream If bolShowProgress Then 'Updates the progress bar objProgress.Value = i End If Next i Close iFile End Sub |