Ví dụ về chuỗi mở rộng
-- Kiểm tra hàm băm
local str = "sozereal"
sys.alert('Dạng thập lục phân của "'..str..'" là: <'..str:to_hex()..'>')
sys.alert('Chuyển <'..str:to_hex()..'> về văn bản: "'..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())
--
-- Mã hóa/Giải mã
local msg = "\5\4\3\2\1\0"
local key = "sozereal"
local emsg = msg:aes128_encrypt(key)
local emsgb64 = emsg:base64_encode()
sys.alert('Dữ liệu nhị phân <'..msg:to_hex()..'>\n AES128 với khóa "'..key..'" -> <'..emsg:to_hex()..'>\n base64: "'..emsgb64..'"')
local tmp = emsgb64:base64_decode()
msg = tmp:aes128_decrypt(key)
sys.alert('Giải mã Base64 "'..emsgb64..'" thành <'..tmp:to_hex()..'>\n Giải mã AES128 bằng khóa "'..key..'" -> <'..msg:to_hex()..'>')
--
-- Tiện ích chuỗi
str = " ha ha,he he,1,3,6 "
new = str:split(",") -- tách theo ','
sys.alert(new[2])
sys.alert(str:rtrim()) -- " ha ha,he he,1,3,6" xóa khoảng trắng ở cuối
sys.alert(str:ltrim()) -- "ha ha,he he,1,3,6 " xóa khoảng trắng ở đầu
sys.alert(str:trim()) -- "ha ha,he he,1,3,6" xóa khoảng trắng ở hai đầu
sys.alert(str:atrim()) -- "haha,hehe,1,3,6" xóa toàn bộ khoảng trắng
Lưu ý: Đoạn mã này sử dụng hàm ngoài chương: sys.alert