发一个收藏的base64加解密函数

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效

Moderators: tmplinshi, arcticir

Post Reply
linpinger
Posts: 21
Joined: 29 Dec 2013, 22:51
Location: 神州
Contact:

发一个收藏的base64加解密函数

Post by linpinger » 11 Aug 2020, 21:08

缘起: 这两天在搞js解密相关的东东,需要一个base64加密函数,找了一圈没有找到纯ahk写的,能用的函数,翻以前的旧脚本,找到一个能用的,在论坛上貌似木有找到,也不知道是谁写的,发出来供大家使用

Code: Select all


oldStringCaseSense := A_StringCaseSense
StringCaseSense On 
Chars = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

strA := "falksjd|fjlks>fksdj,234alsdjaa"
strE := "ZmFsa3NqZHxmamxrcz5ma3NkaiwyMzRhbHNkamFh"
msgbox, % Base64(strA) "`n" strE

StringCaseSense %oldStringCaseSense%
return

Base64(string)
{
   Loop Parse, string
   {
      If Mod(A_Index,3) = 1
         buffer := Asc(A_LoopField) << 16
      Else If Mod(A_Index,3) = 2
         buffer += Asc(A_LoopField) << 8
      Else {
         buffer += Asc(A_LoopField)
         out := out . Code(buffer>>18) . Code(buffer>>12) . Code(buffer>>6) . Code(buffer)
      }
   }
   If Mod(StrLen(string),3) = 0
      Return out
   If Mod(StrLen(string),3) = 1
      Return out . Code(buffer>>18) . Code(buffer>>12) "=="
   Return out . Code(buffer>>18) . Code(buffer>>12) . Code(buffer>>6) "="
}

InvBase64(code)
{
   StringReplace code, code, =,,All
   Loop Parse, code
   {
      If Mod(A_Index,4) = 1
         buffer := DeCode(A_LoopField) << 18
      Else If Mod(A_Index,4) = 2
         buffer += DeCode(A_LoopField) << 12
      Else If Mod(A_Index,4) = 3
         buffer += DeCode(A_LoopField) << 6
      Else {
         buffer += DeCode(A_LoopField)
         out := out . Chr(buffer>>16) . Chr(255 & buffer>>8) . Chr(255 & buffer)
      }
   }
   If Mod(StrLen(code),4) = 0
      Return out
   If Mod(StrLen(code),4) = 2
      Return out . Chr(buffer>>16)
   Return out . Chr(buffer>>16) . Chr(255 & buffer>>8)
}

Code(i)     ; <== Chars[i & 63], 0-base index
{
   Global Chars
   StringMid i, Chars, (i&63)+1, 1
   Return i
}

DeCode(c)   ; c = a char in Chars ==> position [0,63]
{
   Global Chars
   Return InStr(Chars,c,1) - 1
}

laozhhaiJohn
Posts: 24
Joined: 20 Mar 2021, 18:18

Re: 发一个收藏的base64加解密函数

Post by laozhhaiJohn » 28 Mar 2021, 10:08

感谢分享,下来试试。
Post Reply

Return to “脚本函数”