<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Incama</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Incama"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Incama"/>
	<updated>2026-04-16T04:51:14Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=EncodeString&amp;diff=73679</id>
		<title>EncodeString</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=EncodeString&amp;diff=73679"/>
		<updated>2022-01-19T19:38:40Z</updated>

		<summary type="html">&lt;p&gt;Incama: Added a small tip about the performance implications of aes128 vs tea&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{New feature/item|3.0156|1.5.5|11849|&lt;br /&gt;
This function encodes a [[string]] using the specified algorithm. The counterpart of this function is [[decodeString]].&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string encodeString ( string algorithm, string input, table options [, function callback ] )  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''algorithm:''' The algorithm to use.&lt;br /&gt;
*'''input:''' The input to encode.&lt;br /&gt;
*'''options:''' A [[table]] with options and other necessary data for the algorithm, as detailed below.&lt;br /&gt;
&lt;br /&gt;
===Options for each algorithm===&lt;br /&gt;
* ''tea'' ([https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm Tiny Encryption Algorithm])&lt;br /&gt;
** '''key''': a key to encode the input with.&lt;br /&gt;
{{Added feature/item|1.5.9|1.5.8|20898|&lt;br /&gt;
* ''aes128'' ([https://en.wikipedia.org/wiki/Advanced_Encryption_Standard Advanced Encryption Standard] in CTR mode)&lt;br /&gt;
** '''key''': a key to encode the input with (must be 16 characters long).&lt;br /&gt;
|20898}}&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
===Returns for each algorithm===&lt;br /&gt;
* ''tea'' &lt;br /&gt;
** '''encodedString''': the encoded string if successful, ''false'' otherwise. If a callback was provided, ''true'' is returned immediately, and the encoded string is passed as an argument to the callback.&lt;br /&gt;
{{New items|3.0159|1.5.8|&lt;br /&gt;
* ''aes128'' &lt;br /&gt;
** '''encodedString''': the encoded string if successful, ''false'' otherwise. If a callback was provided, ''true'' is returned immediately, and the encoded string is passed as an argument to the callback.&lt;br /&gt;
** '''iv''' ([https://en.wikipedia.org/wiki/Initialization_vector Initialization vector]): this is a string generated by the encryption algorithm that is needed to decrypt the message by [[decodeString]]. If a callback was provided, ''true'' is returned immediately, and the ''iv'' is passed as an argument to the callback.&lt;br /&gt;
|20898}}&lt;br /&gt;
&lt;br /&gt;
==Example== &lt;br /&gt;
Adds an ''/encode'' command 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
addCommandHandler(&amp;quot;encode&amp;quot;, &lt;br /&gt;
    function(player, _, algorithm, key, ...)&lt;br /&gt;
        if algorithm and key then&lt;br /&gt;
            local text = table.concat({...}, &amp;quot; &amp;quot;)&lt;br /&gt;
            if type(text) == &amp;quot;string&amp;quot; and text ~= &amp;quot;&amp;quot; then&lt;br /&gt;
                local encoded = encodeString(algorithm, text, { key = key })&lt;br /&gt;
                if encoded then&lt;br /&gt;
                    outputChatBox(&amp;quot;The result of &amp;quot; .. algorithm .. &amp;quot; encoding is: &amp;quot; .. encoded, player)&lt;br /&gt;
                else&lt;br /&gt;
                    outputChatBox(&amp;quot;Failed to encode. Make sure that all arguments are valid.&amp;quot;, player, 255, 0, 0)&lt;br /&gt;
                end&lt;br /&gt;
            else&lt;br /&gt;
                outputChatBox(&amp;quot;Please specify text in the command.&amp;quot;, player, 255, 0, 0)&lt;br /&gt;
            end&lt;br /&gt;
        else&lt;br /&gt;
            outputChatBox(&amp;quot;Invalid algorithm and/or key.&amp;quot;, player, 255, 0, 0)&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Incama</name></author>
	</entry>
</feed>