--Language "Lua",
-- Code (Morse)
--Notes, It only work on upper Letters
-- It does not work for unknown chars and white spaces
-- It is a morse code so only numbers, Upper letters and Punctuation are allowed.
-- Code (Morse)
--Notes, It only work on upper Letters
-- It does not work for unknown chars and white spaces
-- It is a morse code so only numbers, Upper letters and Punctuation are allowed.
_G["Morse"] = {
--Letters:
["A"] = ".-", ['B'] = "-...", ['C'] = "-.-.", ['D'] = "-..", ['E'] = ".", ['F'] = "..-.", ['G'] = "--.",
['H'] = "....", ['I'] = "..", ['J'] = ".---", ['K'] =
"-.-", ['L'] = ".-..", ['M'] = "--", ['N'] = "-.", ['O'] = "---", ['P'] = ".--.", ['Q'] = "--.-", ['R'] = ".-.",
['S'] = "...", ['T'] = "-", ['U'] =
"..-", ['V'] = "...-", ['W'] = ".--", ['X'] = "-..-", ['Y'] = "-.--", ['Z'] = "--..",
--Now Numbers:
["1"] = "----", ["2"] = "---", ["3"] = "--", ["4"] = "-", ["5"] = ".....",
["6"] = "-....", ["7"] = "--...", ["8"] = "---..", ["9"] = "----.", ["0"] = "-----",
--Also Punctuation:
["."] = ".-.-.-", [","] = "--..--", ["?"] = "..--..", ["`"] = ".----.", ["!"] = "-.-.--", ["/"] = "-..-.",
["("] = "-.--.", [")"] = "-.--.-", ["&"] = ".-...", [":"] = "---...", [";"] = "-.-.-.", ["="] = "-...-",
["+"] = ".-.-.", ["-"] = "-....-", ["_"] = "..--.-", ["\""] = ".-..-.",
["$"] = "...-..-", ["@"] = ".--.--.", ["¿"] = "..-.-",
["¡"] = "--..-"
}
setmetatable(_G["Morse"], { __call = function(a, b, ...)
return ({ string.gsub(b, ".", function(c) return (a[c] and _G["Morse"][c] .. " ") or c end) })[1]
end }) -- usage Morse("HELLO, WORLD !")
-- e.g:Morse = _G["Morse"]("HELLO, WORLD !") -- calling the metatable
print(Morse)
-- output: .... . .-.. .-.. --- --..-- .-- --- .-. .-.. -.. -.-.---- Language (Lua)
-- Code ( A triangle in random symbols ).
-- Code ( A triangle in random symbols ).
long = 10 -- the length of the triangle.
do
local d = {"$", "#", "&", "%", "!", "*", "~", ";", ":", "=", "@"}
local r = string.char()
local n = string.char(10)
local u = string.char(32)
local i = 0x01
local c = (function(s, e)
for _ = 1, e do
s = s .. d[math.random(1, #d)]
end
return s
end)(string.char(), long)
while (i < #c) do
r = r .. u:rep(#c - i) .. (function(s)
for _ = 0x01, i do
s = s .. d[math.random(1, #d)] .. d[math.random(1, #d)]
end
return s
end)(string.char()) .. n
i = i + 0x01
end
results = r
end
print(results) -- outputing the result.-- Language (Lua)
-- Code ( a reverseir for Arabic letters since they are 2 bytes each ).
-- Code ( a reverseir for Arabic letters since they are 2 bytes each ).
reverseArabian = function( text )-- e.g :
if not text then return false, 'no text provided ?' end
local t, d, i, p = {}, {}, 1, 1
for _ in string.gmatch( text, '(.)' ) do
a = text:sub( i, -1 )
if i == p then
if not (_:match( '[%a+%d+%p+%s*]+' )) and string.match( string.byte( _ ), '[128-193]+' ) then
t[#t + 1] = string.sub( a, 1, 1 ) .. string.sub( a, 2, 2 )
p = p + 1
else
t[#t + 1] = _
end
i, p = i + 1, p + 1
else
i = i + 1
end
end
for i = #t, 1, -1 do d[#d + 1] = t[i] end -- the reverse part.
return table.concat( d )
end
text = 'مرحبا كيف حالك !'-- output: ! كلاح فيك ابحرم
print( reverseArabian( text ) )