我需要随机化0-1,A-Z, - 和_的字符集。小写不能成为它的一部分。然后xor加密它然后最终xor解密它。我对xor加密逻辑没有任何问题,因为它可以使用标准strconv(text,vbUnicode)工作正常 - 除了我得到的结果不是可接受的字符 - 但我遇到了如何解决问题在我的字符集中使用填充。或者,我认为这一切都错了,应该仍然使用strconv并以某种方式限制结果?
所以为了解决这个问题,我目前正在尝试制作一个只使用我提到的字符的自定义转换功能。由于我只有38个字符,我知道我需要使用填充,因此将其设置为2,但我完全不知道如何帮助。如果我将26个等号添加为填充以使其达到因子2(38-> 64),我仍然不确定当它进行转换时该怎么做并且在0-63可能性范围内提出38+ 。这里的任何帮助肯定会受到赞赏!
我确实尝试复制最后26个字符的字符串表,但是这显然会在解密时中断,因为因为我处于第38位而产生的A会被转换回值为0.
所以我基本上有这个:
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
(并且只是为了避开不可避免的问题......不,这并不需要是安全的。它不是用来锁门。它的目的是非常简单地隐藏我完全明白,如果他们找到它,它就很难找到,它会以轻柔的推动打开。)
感谢您的帮助!