Hi, I am using a XorC Byte function as part of an encryption macro. The problem is that the function is resulting in a Line feed or New line character in the encrypted string which is sent to a text file and when decrypted causes problems. eg...
Once the function has been run, you will see that the encrypted string contains a line feed or new line character.
Can anyone explain why and how to ensure that it doesnt occur for a variable serial as it is read from the PC harddrive ?
Code:
serial = 1741833591
insertdatastring = sdait,hs8it,rf88i,s88fi,ni888,888cg,8u888,888l8,8t888
encoded = XorC(insertdatastring, serial)
Function XorC(ByVal sData As String, ByVal sKey As String) As String
Dim l As Long, i As Long, byIn() As Byte, byOut() As Byte, byKey() As Byte
Dim bEncOrDec As Boolean
'confirm valid string and key input:
If Len(sData) = 0 Or Len(sKey) = 0 Then XorC = "Invalid argument(s) used": Exit Function
'check whether running encryption or decryption (flagged by presence of "xxx" at start of sData):
If Left$(sData, 3) = "xxx" Then
bEncOrDec = False 'decryption
sData = Mid$(sData, 4)
Else
bEncOrDec = True 'encryption
End If
'assign strings to byte arrays (unicode)
byIn = sData
byOut = sData
byKey = sKey
l = LBound(byKey)
For i = LBound(byIn) To UBound(byIn) - 1 Step 2
byOut(i) = ((byIn(i) + Not bEncOrDec) Xor byKey(l)) - bEncOrDec 'avoid Chr$(0) by using bEncOrDec flag
l = l + 2
If l > UBound(byKey) Then l = LBound(byKey) 'ensure stay within bounds of Key
Next i
XorC = byOut
If bEncOrDec Then XorC = "xxx" & XorC 'add "xxx" onto encrypted text
End Function
Once the function has been run, you will see that the encrypted string contains a line feed or new line character.
Can anyone explain why and how to ensure that it doesnt occur for a variable serial as it is read from the PC harddrive ?