I need to randomize character sets of 0-1, A-Z, -, and _. Lowercase cannot be part of it. Then xor encrypt it then eventually xor decrypt it. I don't have any issues with the xor encrypt logic as it will work fine with standard strconv(text,vbUnicode) - other than I get results that aren't the acceptable characters - but I am having trouble with how to use padding in my character set. Or alternately, I am going about this all wrong and should still use strconv and somehow restrict the results?
So to tackle this I am currently trying to make a custom conversion function that only uses the characters I mentioned. Since I only have 38 characters I know I need to use padding the get it to a factor of 2 but I am completely lost on how that would help. If I add in 26 equals signs as padding to get it to factor of 2 (38->64) I still am not sure what to do when it does a conversion and comes up with 38+ on the 0-63 scale of possibilities. Any help here would definitely be appreciated!
I did try just duplicating the string table for the last 26 characters but that obviously breaks on the decrypt since an A that originated because i was in position 38 would get translated back as having a value of 0.
So I basically have this:
Function Convert(sText As Variant, sDirection As String)
Dim aCharMap() As Variant
Dim aText() As Variant, bText() As String
Dim iText() As Byte, i As Integer, j As Integer, k As Integer
aCharMap = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_")
If sDirection = "ToBinary" Then
ReDim aText(Len(sText) - 1)
ReDim iText(Len(sText) - 1)
For i = 1 To Len(sText)
aText(i - 1) = UCase(Mid$(sText, i, 1))
Next
For j = 0 To UBound(aText)
For k = 0 To UBound(aCharMap)
If aCharMap(k) = aText(j) Then
iText(j) = CByte(k)
Exit For
End If
Next k
Next j
Convert = iText()
ElseIf sDirection = "FromBinary" Then
bText = Split(sText, ",")
ReDim aText(LBound(bText) To UBound(bText))
For j = 0 To UBound(bText)
aText(j) = aCharMap(bText(j))
Next
Convert = Join(aText(), "")
End If
End Function
(And just to head off the inevitable question... No, this doesn't need to be secure. It isn't intended as a lock on a door. It is intended to very simply hide the door. I completely understand that if they look for it, it won't be hard to find and it will open right up with a gentle nudge.)
Thanks for any help!