Attribute VB_Name ="ModBase64" OptionExplicit 'Powered by barenx Public key(1To3) AsLong PrivateConst base64 ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" PublicSub GenKey()Sub GenKey() Dim d AsLong, phi AsLong, e AsLong Dim m AsLong, x AsLong, q AsLong Dim p AsLong Randomize OnErrorGoTo top top: p =Rnd*10001 If IsPrime(p) =FalseThenGoTo top Sel_q: q =Rnd*10001 If IsPrime(q) =FalseThenGoTo Sel_q n = p * q 1 phi = (p -1) * (q -1) 1 d =Rnd* n 1 If d =0Or n =0Or d =1ThenGoTo top e = Euler(phi, d) If e =0Or e =1ThenGoTo top x = Mult(255, e, n) IfNot Mult(x, d, n) =255Then DoEvents GoTo top ElseIf Mult(x, d, n) =255Then key(1) = e key(2) = d key(3) = n EndIf End Sub PublicFunction Euler()Function Euler(ByVal a AsLong, ByVal b AsLong) AsLong OnErrorGoTo error2 r1 = a: r = b p1 =0: p =1 q1 =2: q =0 n =-1 DoUntil r =0 r2 = r1: r1 = r p2 = p1: p1 = p q2 = q1: q1 = q n = n +1 r = r2 Mod r1 c = r2 r1 p = (c * p1) + p2 q = (c * q1) + q2 Loop s = (b * p1) - (a * q1) If s >0Then x = p1 Else x = (0- p1) + a EndIf Euler = x Exit Function error2: Euler =0 End Function PublicFunction Mult()Function Mult(ByVal x AsLong, ByVal p AsLong, ByVal m AsLong) AsLong y =1 OnErrorGoTo error1 DoWhile p >0 DoWhile (p /2) = (p 2) x = (x * x) Mod m p = p /2 Loop y = (x * y) Mod m p = p -1 Loop Mult = y Exit Function error1: y =0 End Function PublicFunction IsPrime()Function IsPrime(lngNumber AsLong) AsBoolean Dim lngCount AsLong Dim lngSqr AsLong Dim x AsLong lngSqr =Sqr(lngNumber) ' get the int square root If lngNumber <2Then IsPrime =False Exit Function EndIf lngCount =2 IsPrime =True If lngNumber Mod lngCount =0&Then IsPrime =False Exit Function EndIf lngCount =3 For x&= lngCount To lngSqr Step2 If lngNumber Mod x&=0Then IsPrime =False Exit Function EndIf Next End Function PublicFunction Base64_Encode()Function Base64_Encode(DecryptedText AsString) AsString Dim c1, c2, c3 AsInteger Dim w1 AsInteger Dim w2 AsInteger Dim w3 AsInteger Dim w4 AsInteger Dim n AsInteger Dim retry AsString For n =1To LenB(StrConv(DecryptedText, vbFromUnicode)) Step3 c1 = AscB(MidB$(DecryptedText, n, 1)) c2 = AscB(Mid$(DecryptedText, n +1, 1) + ChrB$(0)) c3 = AscB(Mid$(DecryptedText, n +2, 1) + ChrB$(0)) w1 =Int(c1 /4) w2 = (c1 And3) *16+Int(c2 /16) If LenB(StrConv(DecryptedText, vbFromUnicode)) >= n +1Then w3 = (c2 And15) *4+Int(c3 /64) Else w3 =-1 If LenB(StrConv(DecryptedText, vbFromUnicode)) >= n +2Then w4 = c3 And63Else w4 =-1 retry = retry + mimeencode(w1) + mimeencode(w2) + mimeencode(w3) + mimeencode(w4) Next Base64_Encode = retry End Function PublicFunction Base64_Decode()Function Base64_Decode(a AsString) AsString Dim w1 AsInteger Dim w2 AsInteger Dim w3 AsInteger Dim w4 AsInteger Dim n AsInteger Dim retry AsString For n =1ToLen(a) Step4 w1 = mimedecode(Mid$(a, n, 1)) w2 = mimedecode(Mid$(a, n +1, 1)) w3 = mimedecode(Mid$(a, n +2, 1)) w4 = mimedecode(Mid$(a, n +3, 1)) If w2 >=0Then retry = retry + ChrB$(((w1 *4+Int(w2 /16)) And255)) If w3 >=0Then retry = retry + ChrB$(((w2 *16+Int(w3 /4)) And255)) If w4 >=0Then retry = retry + ChrB$(((w3 *64+ w4) And255)) Next Base64_Decode =StrConv(retry, vbUnicode) End Function PublicFunction mimeencode()Function mimeencode(w AsInteger) AsString If w >=0Then mimeencode =Mid$(base64, w +1, 1) Else mimeencode ="" End Function PrivateFunction mimedecode()Function mimedecode(a AsString) AsInteger IfLen(a) =0Then mimedecode =-1: Exit Function mimedecode =InStr(base64, a) -1 End Function PublicFunction Encode()Function Encode(ByVal Inp AsString, ByVal e AsLong, ByVal n AsLong) AsString Dim s AsString s ="" m = Inp If m =""ThenExit Function s = Mult(CLng(Asc(Mid(m, 1, 1))), e, n) For i =2ToLen(m) s = s &"+"& Mult(CLng(Asc(Mid(m, i, 1))), e, n) Next i Encode = Base64_Encode(s) End Function PublicFunction Decode()Function Decode(ByVal Inp AsString, ByVal d AsLong, ByVal n AsLong) AsString St ="" ind = Base64_Decode(Inp) For i =1ToLen(ind) nxt =InStr(i, ind, "+") IfNot nxt =0Then tok =Val(Mid(ind, i, nxt)) Else tok =Val(Mid(ind, i)) EndIf St = St +Chr(Mult(CLng(tok), d, n)) IfNot nxt =0Then i = nxt Else i =Len(ind) EndIf Next i Decode = St End Function