天工维度魔兽争霸开发者社区-全国最大的TJ集中营-原提百万联盟

标题: [垃圾佬] Base64编码 [打印本页]

作者: Rubbish    时间: 2022-2-19 23:40
标题: [垃圾佬] Base64编码
没啥好说的

下面是代码


  1. library Base64
  2.     globals
  3.         private string EncFunc = "(
  4. function(str)
  5. local encstring={[0]='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','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','+','/',}
  6. local decstring={}
  7. for k,v in pairs(encstring) do
  8. decstring[v:byte()]=k
  9. end
  10. local byte=str
  11. if type(str)=='string' then
  12. byte={str:byte(1,#str)}
  13. end
  14. if type(byte)~='table' then
  15. return ''
  16. end
  17. local result={}
  18. local len=#byte
  19. local number=len%3
  20. local num=0
  21. for i=1,len,3 do
  22. num=((byte[i] or 0)<<16)+((byte[i+1] or 0)<<8)+((byte[i+2] or 0)<<0)
  23. for j=3,0,-1 do
  24. local tmp=num>>(j*6)
  25. table.insert(result,encstring[tmp&0x3f])
  26. end
  27. end
  28. if number>0 then
  29. for i=3-number,1,-1 do
  30. result[#result-i+1]='='
  31. end
  32. end
  33. return table.concat(result)
  34. end)
  35. "
  36.         private string DecFunc = "(
  37. function(str)
  38. local encstring={[0]='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','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','+','/',}
  39. local decstring={}
  40. for k,v in pairs(encstring) do
  41. decstring[v:byte()]=k
  42. end
  43. local byte=str
  44. if type(str)=='string' then
  45. byte={str:byte(1,#str)}
  46. end
  47. if type(byte)~='table' then
  48. return ''
  49. end
  50. local result={}
  51. local len=#byte
  52. local num=0
  53. local number=0
  54. local data=str:gsub('=',function()
  55. number=number+1
  56. end)
  57. if len%4~=0 then
  58. return ''
  59. end
  60. for i=1,len,4 do
  61. num=((decstring[byte[i]] or 0)<<18)+((decstring[byte[i+1]] or 0)<<12)+((decstring[byte[i+2]] or 0)<<6)+((decstring[byte[i+3]] or 0)<<0)
  62. for j=2,0,-1 do
  63. local tmp=num>>(j*8)
  64. table.insert(result,tmp&0xff)
  65. end
  66. end
  67. local max=#result
  68. if number>0 then
  69. for i=number,1,-1 do
  70. result[max-i+1]=nil
  71. end
  72. end
  73. return string.char(table.unpack(result))
  74. end)
  75. "
  76.     endglobals

  77.     function Base64EncString takes string s returns string
  78.         local string func   = EncFunc + "('" + s + "')"
  79.         local string result = EXExecuteScript( func )
  80.         return result
  81.     endfunction

  82.     function Base64DecString takes string s returns string
  83.         local string func   = DecFunc + "('" + s + "')"
  84.         local string result = EXExecuteScript( func )
  85.         return result
  86.     endfunction

  87. endlibrary
复制代码



下面是测试代码:
function B2S takes boolean bool return string
    if bool then
        return "true"
    endif
    return "false"
endfunction

function Trig_Base_64Actions takes nothing returns nothing
    local string ChatString = GetEventPlayerChatString( )
    local string EncString  = ""
    local string DecString  = ""
    if EncString != "" or EncString != null then
        call BJDebugMsg( "Base64 加密字符串 -> " + ChatString )
        set EncString = Base64EncString( ChatString )
        call BJDebugMsg( "Base64 加码 -> " + EncString )
        set DecString = Base64DecString( EncString )
        call BJDebugMsg( "Base64 解码 -> " + DecString )
        call BJDebugMsg( "是否成功 -> " + B2S( ChatString == DecString ) )
    endif
endfunction

//===========================================================================
function InitTrig_Base_64 takes nothing returns nothing
    set gg_trg_Base_64 = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(gg_trg_Base_64, Player(0), "", true)
    call TriggerAddAction(gg_trg_Base_64, function Trig_Base_64Actions)
endfunction

作者: 提百万    时间: 2022-2-19 23:47
小白提问,这个有啥用
作者: Rubbish    时间: 2022-2-20 00:24
提百万 发表于 2022-2-19 23:47
小白提问,这个有啥用

啥用都没有




欢迎光临 天工维度魔兽争霸开发者社区-全国最大的TJ集中营-原提百万联盟 (http://bbs.mvprpg.com/) Powered by Discuz! X3.4