'从 Base64 改进而来的字符编码
'B64_Alpha 密钥直接用ASC  
'B64_Alpha 值 34--61 ，随机取值，每次编码，结果不同。
Function YF_BaseEncode(ByVal InBuff as String ) as String 
'从 Base64 改进而来，B64_Alpha区直接用ASC  B64_Alpha 值 34--61 
    Dim as UByte   C1 , C2 , c3 ,B64_Alpha
    Dim as Short  w1 , w2 , w3 , w4 
    Dim as Integer n,Tu ,r   
    Dim OutBuff as String 
    Dim as UByte Ptr tS,bA,rE
    If Len(InBuff) =0 Then Exit Function
    Randomize 
    B64_Alpha =Rnd * (61 - 34) + 34

     Tu = Len(InBuff)
     If Tu Mod 3 <> 0 Then  '需要3的倍数
        InBuff &= String(3 - (Tu  Mod 3),0)
     End If
     
     OutBuff=String(Len(InBuff)*4/3,0) '输出
     tS=StrPtr(InBuff)
'     bA=StrPtr(B64_Alpha)
     rE=StrPtr(OutBuff)

     R = -1
       For n = 0 To Len(InBuff)-1 Step 3
          C1 = tS[n]
          C2 = tS[n+1]
          c3 = tS[n+2]
          w1 = Int(C1 / 4)
          w2 = (C1 And 3) * 16 + Int(C2 / 16)
          w3 = (C2 And 15) * 4 + Int(c3 / 64) + (n + 1 >= Tu)
          w4 = (c3 And 63) + (n + 2 >= Tu)
          R += 1: re[R] = w1 + B64_Alpha
          R += 1: re[R] = w2 + B64_Alpha
          R += 1: re[R] = w3 + B64_Alpha
          R += 1: re[R] = w4 + B64_Alpha
       Next
       Function =Chr(B64_Alpha) & OutBuff
End Function