TeaEncode: Difference between revisions
Jump to navigation
Jump to search
m (Error fix at →Example: ;)) |
No edit summary |
||
Line 3: | Line 3: | ||
{{New feature/item|3.0135|1.3.5|6056| | {{New feature/item|3.0135|1.3.5|6056| | ||
This functions performs the [https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm Tiny Encryption Algorithm] on the given string and returns the [https://en.wikipedia.org/wiki/Base64 base64] representation of the encrypted | This functions performs the [https://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm Tiny Encryption Algorithm] on the given string and returns the [https://en.wikipedia.org/wiki/Base64 base64] representation of the encrypted string. | ||
}} | }} | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">string teaEncode ( string | <syntaxhighlight lang="lua">string teaEncode ( string text , string key )</syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*''' | *'''text:''' The string you want to encrypt. (See second example if you want to encode binary data) | ||
*'''key:''' The key that should be used for encryption (Only first 16 characters are used) | *'''key:''' The key that should be used for encryption (Only first 16 characters are used) | ||
===Returns=== | ===Returns=== | ||
Returns the [https://en.wikipedia.org/wiki/Base64 base64] representation of the encrypted | Returns the [https://en.wikipedia.org/wiki/Base64 base64] representation of the encrypted string if the encryption process was successfully completed, ''false'' otherwise. | ||
==Example== | ==Example== | ||
Line 34: | Line 34: | ||
addCommandHandler( "teaencrypt", encryptString ) | addCommandHandler( "teaencrypt", encryptString ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This shows how to use teaEncode/teaDecode with binary data: | |||
<syntaxhighlight lang="lua"> | |||
function teaEncodeBinary( data, key ) | |||
return teaEncode( base64encode( data ), key ) | |||
end | |||
function teaDecodeBinary( data, key ) | |||
return base64decode( teaDecode( data, key ) ) | |||
end | |||
</section> | </section> | ||
==See Also== | ==See Also== | ||
{{Utility functions}} | {{Utility functions}} |
Revision as of 19:26, 27 November 2014
This functions performs the Tiny Encryption Algorithm on the given string and returns the base64 representation of the encrypted string.
Syntax
string teaEncode ( string text , string key )
Required Arguments
- text: The string you want to encrypt. (See second example if you want to encode binary data)
- key: The key that should be used for encryption (Only first 16 characters are used)
Returns
Returns the base64 representation of the encrypted string if the encryption process was successfully completed, false otherwise.
Example
Click to collapse [-]
ClientThis example creates a /teaencrypt command, which performs the TEA on a given string with the specified key, if any.
[lua] function encryptString( cmd, theString, theKey ) if ( theString ) then if ( not theKey ) then theKey = string.rep( string.char( math.random( string.byte( "a" ), string.byte( "Z" ) ) ), 10 ) -- Generate a random key of 10 characters if no key was passed in as an argument end local encodedString = teaEncode( theString, theKey ) -- Encode the string with the key outputChatBox( "The encoded string is: " .. tostring( encodedString ) .. " (used key: " .. theKey .. ")" ) else outputChatBox( "Syntax: /" .. cmd .. " [string] <[key]>" ) end end addCommandHandler( "teaencrypt", encryptString )
This shows how to use teaEncode/teaDecode with binary data: <syntaxhighlight lang="lua"> function teaEncodeBinary( data, key )
return teaEncode( base64encode( data ), key )
end function teaDecodeBinary( data, key )
return base64decode( teaDecode( data, key ) )
end
See Also
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace