TeaEncode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added to the needs example category)
(Added example)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Needs Example}}
{{Server_client function}}
{{Server_client function}}


Line 18: Line 17:


==Example==
==Example==
<section name="Client" class="client" show="true">
This example creates a /teaencrypt command, which performs the TEA on a given string with the specified key, if any.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Todo
function encrypt(cmd, string, key)
    if string then
        if not key then
            key = string.rep(string.char(math.random(string.byte("a"), string.byte("Z"))), 10) -- Generate a random key of 10 characters
        end
        local encodedString = teaEncode(string, key) -- Encode the string with the key
        outputChatBox("The encoded string is: " .. encodedString .. " (used key: " .. key .. ")")
    else
        outputChatBox("Syntax: /" .. cmd .. " (string).")
    end
end
addCommandHandler("teaencrypt", encrypt)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}

Revision as of 12:40, 18 May 2014

ADDED/UPDATED IN VERSION 1.3.5 r6056:

This functions performs the Tiny Encryption Algorithm on the given string and returns the base64 representation of the encrypted block of data.

Syntax

string teaEncode ( string data, string key )

Required Arguments

  • data: The block of data you want to encrypt
  • key: The key that should be used for encryption

Returns

Returns the base64 representation of the encrypted data if the encryption process was successfully completed, false otherwise.

Example

Click to collapse [-]
Client

This example creates a /teaencrypt command, which performs the TEA on a given string with the specified key, if any.

function encrypt(cmd, string, key)
    if string then
        if not key then
            key = string.rep(string.char(math.random(string.byte("a"), string.byte("Z"))), 10) -- Generate a random key of 10 characters
        end
        local encodedString = teaEncode(string, key) -- Encode the string with the key
        outputChatBox("The encoded string is: " .. encodedString .. " (used key: " .. key .. ")")
    else
        outputChatBox("Syntax: /" .. cmd .. " (string).")
    end
end
addCommandHandler("teaencrypt", encrypt)

See Also