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
Manual Review Required
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
string encodeString ( string algorithm, string input, table options, function callback )Required Arguments
- algorithm: The algorithm to use.
- input: The input to encode.
- options: A table with options and other necessary data for the algorithm, as detailed below.
- callback: providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.
Returns
- string: value
Code Examples
shared
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)See Also
Utility Functions
- addDebugHook
- bitAnd
- bitArShift
- bitExtract
- bitLRotate
- bitLShift
- bitNot
- bitOr
- bitReplace
- bitRRotate
- bitRShift
- bitTest
- bitXor
- createTrayNotification
- debugSleep
- decodeString
- deref
- downloadFile
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getFPSLimit
- getKeyboardLayout
- getLocalization
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getProcessMemoryStats
- getRealTime
- getServerIp
- getTickCount
- getTimerDetails
- getTimers
- gettok
- getUserdataType
- getVersion
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isShowCollisionsEnabled
- isShowSoundEnabled
- isTimer
- isTimerPaused
- isTransferBoxAlwaysVisible
- isTransferBoxVisible
- isTrayNotificationEnabled
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- ref
- removeDebugHook
- resetTimer
- setClipboard
- setDevelopmentMode
- setFPSLimit
- setTimer
- setTimerPaused
- setTransferBoxVisible
- setWindowFlashing
- sha256
- showCol
- showSound
- split
- teaDecode
- teaEncode
- tocolor
- toJSON
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub