LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
GPO GPO is offline
external usenet poster
 
Posts: 12
Default Xors and byte arrays

Rob Bovey posted a bit of code to http://www.devx.com/tips/Tip/5676

Function szEncryptDecrypt(ByVal szData As String) As String
''' This key value can be changed to alter the
''' encryption, but it must be the same for both
''' encryption and decryption.
Const KEY_TEXT As String = "ScratchItYouFool"
''' The KEY_OFFSET is optional, and may be any
''' value 0-64.
''' Likewise, it needs to be the same coming/going.
Const KEY_OFFSET As Long = 38

Dim bytKey() As Byte
Dim bytData() As Byte
Dim lNum As Long
Dim szKey As String

For lNum = 1 To ((Len(szData) \ Len(KEY_TEXT)) + 1)
szKey = szKey & KEY_TEXT
Next lNum

bytKey = Left$(szKey, Len(szData))
bytData = szData

For lNum = LBound(bytData) To UBound(bytData)
If lNum Mod 2 Then
bytData(lNum) = bytData(lNum) Xor (bytKey(lNum) _
+ KEY_OFFSET)
Else
bytData(lNum) = bytData(lNum) Xor (bytKey(lNum) _
- KEY_OFFSET)
End If
Next lNum

szEncryptDecrypt = bytData
End Function


I'm finding that it generates an awful lot of overflow errors because the
value being returned to bytData(lNum) is not in a byte range. There seem to
be dozens of scenarios where varying the key and the key offset (seemingly
within the expected parameters) that bytData(lNum) Xor (bytKey(lNum) -
KEY_OFFSET) cannot return byte data OR that the final bytData cannot be
converted back to a string.

Am I missing something here?

Do I need to do some preliminary checks before setting the constants and
passing data into the function?

Regards

GPO

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Byte Codes Jakobshavn Isbrae Excel Discussion (Misc queries) 0 November 11th 06 03:51 PM
Passing Byte array to DLL Tom Excel Programming 2 May 4th 06 04:23 PM
Excel Byte Calculation [email protected] Excel Worksheet Functions 2 January 5th 06 03:26 AM
byte order reversal in spreadsheet CuriousMark Excel Programming 3 March 22nd 05 07:59 PM
Double-byte challenges. Please help! Douglas Gennetten[_2_] Excel Programming 0 January 15th 04 02:20 AM


All times are GMT +1. The time now is 03:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"