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 Inputs: EncDedString: strSource As String (String to work with) Optional strKey As String = "jhGd&34" (The key) EncDecFile: strSource As String (full path of file to work with) Optional bolShowProgress As Boolean = False (self-Explanatory) Optional objProgress As ProgressBar (The actual Prog.Bar) Returns: String (The result string) Assumes: This is an ecryption/decryption algorithm. Even if simple, it can completely render a file useless. Use it with care. The mechanism by wich this code functions does not trap erroneous keys. Since it uses a Random Xor, if you by any instance try to decrypt a file with a mistaken key, you'll be in fact encrypting it again. ...and Do not use it on system files! |