TeaDecode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Example update)
Line 17: Line 17:
==Example==
==Example==
<section name="Example 1" class="client" show="true">
<section name="Example 1" class="client" show="true">
This example creates a /teadecrypt command, which reverts the TEA on a given string with the specified key, if any.
This example creates a /teadecrypt command, which reverts the TEA on a given string with the specified key.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
[lua]
[lua]
function decrypt(cmd, theString, key)
function decryptString( cmd, theString, theKey )
     if theString then
     if ( theString ) and ( theKey ) then
        if not key then
         local decodedString = teaDecode( theString, theKey ) -- Decode the string with the key
            key = string.rep(string.char(math.random(string.byte("a"), string.byte("Z"))), 10) -- Generate a random key of 10 characters
         outputChatBox( "The decoded string is: " .. tostring( decodedString ) )
        end
         local decodedString = teaDecode(theString, key) -- Encode the string with the key
         outputChatBox("The encoded string is: " .. encodedString .. " (used key: " .. key .. ")")
     else
     else
         outputChatBox("Syntax: /" .. cmd .. " (string) [key].")
         outputChatBox( "Syntax: /" .. cmd .. " [string] [key]" )
     end
     end
end
end
addCommandHandler("teadecrypt", decrypt)
addCommandHandler( "teadecrypt", decryptString )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 21:49, 4 August 2014

ADDED/UPDATED IN VERSION 1.3.5 r6056:

This function decrypts given base64 representation of encrypted data using the Tiny Encryption Algorithm.

Syntax

string teaDecode ( string data, string key )

Required Arguments

  • data: The block of data you want to decrypt
  • key: The key that should be used for decryption (Only first 16 characters are used)

Returns

Returns string containing the decrypted data if the decryption process was successfully completed, false otherwise.

Example

Click to collapse [-]
Example 1

This example creates a /teadecrypt command, which reverts the TEA on a given string with the specified key.

[lua]
function decryptString( cmd, theString, theKey )
    if ( theString ) and ( theKey ) then
        local decodedString = teaDecode( theString, theKey ) -- Decode the string with the key
        outputChatBox( "The decoded string is: " .. tostring( decodedString ) )
    else
        outputChatBox( "Syntax: /" .. cmd .. " [string] [key]" )
    end
end
addCommandHandler( "teadecrypt", decryptString )

See Also