Dr01d3k4Join Date: 2007-10-11 Post Count: 17916 |
I would have to use an internet translator for binary, but for morse I use my custom translator made in Lua which can use all letters, numbers and some punctuation:
convert = {
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 = "--..",
}
punc = {
{".", "._._._"},
{",", "__..__"},
{"?", "..__.."},
{"'", ".____."},
{"!", "_._.__"},
{"/", "_.._."},
{"(", "_.__."},
{")", "_.__._"},
{"&", "._..."},
{":", "___..."},
{";", "_._._."},
{"=", "_..._"},
{"+", "._._."},
{"-", "_...._"},
{"_", "..__._"},
{"\"", "._.._."},
{"$", "..._.._"},
{"@", ".__._."},
}
numbers = {
{1, ".----"},
{2, "..---"},
{3, "...--"},
{4, "....-"},
{5, "....."},
{6, "-...."},
{7, "--..."},
{8, "---.."},
{9, "----."},
{0, "-----"},
}
function _G.tomorse(str)
local sstr = tostring(str)
if (sstr == nil) then return str end
local a = ""
for b = 1, #str do
local d = string.lower(string.sub(str, b, b))
if (d == " ") then
a = a.."/ "
elseif (tonumber(d) ~= nil) then
for c = 1, #numbers do
if (numbers[c][1] == tonumber(d)) then
a = a..""..numbers[c][2].." "
end
end
else
for i, v in pairs(convert) do
if (d == i) then
a = a..""..v.. " "
end
end
for _, e in pairs(punc) do
if (d == e[1]) then
a = a..""..e[2].." "
end
end
end
end
return a
end
function _G.tostr(m)
local sm = tostring(m)
if (sm == nil) then return m end
local am = string.gsub(sm, " ", "|")
local tbl = { }
local curstr = ""
local str = ""
for a = 1, #am do
if (string.sub(am, a, a) ~= "|") then
curstr = curstr..""..string.sub(am, a, a)
else
table.insert(tbl, curstr)
curstr = ""
end
end
for b = 1, #tbl do
for c = 1, #numbers do
if (tbl[b] == numbers[c][2]) then
str = str..""..numbers[c][1].. ""
end
end
for i, v in pairs(convert) do
if (tbl[b] == v) then
str = str..""..tostring(i)
end
end
for _, d in pairs(punc) do
if (tbl[b] == d[2]) then
str = str..""..tostring(d[1])
end
end
if (tbl[b] == "/") then
str = str.." "
end
end
return str
end
local a = tomorse("Input the string you want to morse here")
local b = tostr("Input the morse you want to string here")
print(a, "| |", b) |