Problem porting Open, Put, Get code from 2003 to 2007

dribei16

New Member
Joined
Oct 15, 2010
Messages
22
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:

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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top