encodeString | Multi Theft Auto: Wiki Skip to content

encodeString

Client-side
Server-side
Shared
Needs checking

This function was partially migrated from the old wiki. Please review manually:

  • Missing section: Options for each algorithm
  • Missing section: Returns for each algorithm

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function encodes a string using the specified algorithm. The counterpart of this function is decodeString.

Tip

If it doesn't matter which algorithm you use for the encoding, keep in mind that aes128 uses hardware acceleration so it may outperform the tea algorithm on most processors.

Syntax

encodeString ( )

Code Examples

server

Adds an/encodecommand in which you can provide an algorithm, key and data to encode. Below is the example provided as both server-side and client-side variations.

addCommandHandler("encode", function(player, _, algorithm, key, ...)
if not algorithm or not key then
outputChatBox("Invalid algorithm and/or key.", player, 255, 0, 0)
return
end
local text = table.concat({...}, " ")
if type(text) ~= "string" or text == "" then
outputChatBox("Please specify text in the command.", player, 255, 0, 0)
return
end
local encoded = encodeString(algorithm, text, { key = key })
if not encoded then
outputChatBox("Failed to encode. Make sure that all arguments are valid.", player, 255, 0, 0)
return
end
outputChatBox("The result of " .. algorithm .. " encoding is: " .. encoded, player)
end)