Extended string samples
-- Hash checks
local str = "sozereal"
sys.alert('"'..str..'" in hex is: <'..str:to_hex()..'>')
sys.alert('<'..str:to_hex()..'> back to text: "'..str:to_hex():from_hex()..'"')
sys.alert('MD5("'..str..'") = '..str:md5())
sys.alert('SHA1("'..str..'") = '..str:sha1())
local binstr = "\0\1\2\3\4\5"
sys.alert('<'..binstr:to_hex()..'> MD5 = '..binstr:md5())
sys.alert('<'..binstr:to_hex()..'> SHA1 = '..binstr:sha1())
--
-- Encrypt/Decrypt
local msg = "\5\4\3\2\1\0"
local key = "sozereal"
local emsg = msg:aes128_encrypt(key)
local emsgb64 = emsg:base64_encode()
sys.alert('Binary <'..msg:to_hex()..'>\n AES128 with key "'..key..'" -> <'..emsg:to_hex()..'>\n base64: "'..emsgb64..'"')
local tmp = emsgb64:base64_decode()
msg = tmp:aes128_decrypt(key)
sys.alert('"'..emsgb64..'" base64-decoded <'..tmp:to_hex()..'>\n AES128 with key "'..key..'" decrypted -> <'..msg:to_hex()..'>')
--
-- String helpers
str = " 哈哈,he he,1,3,6 "
new = str:split(",") -- split by ','
sys.alert(new[2])
sys.alert(str:rtrim()) -- " 哈哈,he he,1,3,6" remove trailing spaces
sys.alert(str:ltrim()) -- "哈哈,he he,1,3,6 " remove leading spaces
sys.alert(str:trim()) -- "哈哈,he he,1,3,6" trim both sides
sys.alert(str:atrim()) -- "哈哈,hehe,1,3,6" remove all whitespaces
Note: This snippet uses function outside of this chapter: sys.alert