Hi,
I wrote some code in Excel 2003 to Xor the bytes in a file with the ones in a key. It worked nicely, and would decrypt okay. But when I use the exact same code in Excel 2007 or 2010 it doesn't work. The decrypted file is created but it's contents are thrashed. Does anyone know why? Here goes the code:
PS: Yes, I used real paths in 'path' and 'resultpath'.
PS2: To decrypt I would just put 'resultpath' in 'path' and a path to a new file in 'resultpath'
Thanks
I wrote some code in Excel 2003 to Xor the bytes in a file with the ones in a key. It worked nicely, and would decrypt okay. But when I use the exact same code in Excel 2007 or 2010 it doesn't work. The decrypted file is created but it's contents are thrashed. Does anyone know why? Here goes the code:
Code:
Public Sub encrypt()
Dim keyCounter As Integer
Dim key As String
Dim resultpath As String
Dim bkey() As Byte
Dim bResul As Byte
Dim path As String
Dim nFileNum As Integer, nFileNum2 As Integer, bytTemp As Byte
resultpath = "C:\..."
path = "C:\..."
key = "somekey"
bkey = key
keyCounter = LBound(bkey)
nFileNum = FreeFile()
Open path For Binary As nFileNum
nFileNum2 = FreeFile()
Open resultpath For Binary As nFileNum2
For i = LBound(bkey) To UBound(bkey)
bResul = bkey(i)
Put nFileNum2, , bResul
Next i
Do While Not EOF(nFileNum)
Get nFileNum, , bytTemp
If keyCounter > UBound(bkey) Then
keyCounter = LBound(bkey)
End If
bResul = bytTemp Xor bkey(keyCounter)
Put nFileNum2, , bResul
keyCounter = keyCounter + 1
Loop
Close nFileNum
Close nFileNum2
End Sub
PS: Yes, I used real paths in 'path' and 'resultpath'.
PS2: To decrypt I would just put 'resultpath' in 'path' and a path to a new file in 'resultpath'
Thanks