|
Sub nn() Dim Count As Integer, KeyPos As Integer, KeyLen As Integer, SrcAsc As Integer, test As String, offset As Integer, TmpSrcAsc, SrcPos Dim aa As Integer 'Dim bb As String Action = "加密" Key = Range("0") Src = Range("塘") KeyLen = Len(Key) If Action = "加密" Then Randomize '初始化随机数生成器 'offset = (Rnd * 100000 Mod 65535) + 1 offset = 0 test = Hex$(offset) '用Hex得到 16 进制值 If Len(test) = 3 Then '用Len得知某字符串的长度 test = "0" + test Else If Len(test) = 2 Then '用Len得知某字符串的长度 test = "00" + test Else If Len(test) = 1 Then test = "000" + test End If End If SrcPos = 1 '用Asc返回字符串首字母的字符值(ASCII 值) '用Mid得到某个字符串中的几个字符 '用Mod对两数作除法运算返回其余数 aa = Asc(Mid$(Src, SrcPos, 1)) MsgBox aa If aa < 0 Then aa = aa + 65535 Else End If MsgBox aa SrcAsc = (aa + offset) Mod 65535 MsgBox SrcAsc If KeyPos < KeyLen Then KeyPos = KeyPos + 1 Else KeyPos = 1 SrcAsc = SrcAsc Xor Asc(Mid$(Key, KeyPos, 1)) ' MsgBox SrcAsc bb = Hex$(SrcAsc) If Len(bb) = 3 Then '用Len得知某字符串的长度 bb = "0" + bb Else If Len(bb) = 2 Then '用Len得知某字符串的长度 bb = "00" + bb Else If Len(bb) = 1 Then bb = "000" + bb End If End If test = test + Format$(Hex$(SrcAsc), "@@@@") offset = SrcAsc Else End If
'公式 = test End Sub
这是根据xiaog兄提供的代码修改的,其中红色部分无法运行,但下面的代码却可以运行 Public Sub ff() aa = Asc(Mid$("塘", 1, 1)) MsgBox aa If aa < 0 Then aa = aa + 65535 Else End If MsgBox aa End Sub 请高手指点!!!!
[此贴子已经被作者于2008-8-15 22:37:04编辑过] |