Posted 12 June 2012 - 09:18 AM
I'm making a program that can convert a lua program into Binary, then when you wanna run it it converts it back and reads it.
I currently got numbers (using binary) for the translation thing.
The code is:
I currently got numbers (using binary) for the translation thing.
The code is:
local aTranslations = {}
local bTranslations = {}
function addPatch( letter, trans )
aTranslations[letter] = trans
bTranslations[trans] = letter
end
addPatch("1", "00110001") --Translate Numbers
addPatch("2", "00110010")
addPatch("3", "00110011")
addPatch("4", "00110100")
addPatch("5", "00110101")
addPatch("6", "00110110")
addPatch("7", "00110111")
addPatch("8", "00111000")
addPatch("9", "00111001")
addPatch("0", "00110000")
print("Option: (1=Number to Binary) (2=Binary to Number)")
i2nput = read()
shell.run("clear") --I like to expose people to viruses that use names like "clear" :3
if i2nput == "1" or i2nput == "2" then
write("Translate: ")
input = read()
if i2nput == "1" then
for i=1,string.len(input) do
if aTranslations[string.sub(input, i, i)] then
write(aTranslations[string.sub(input, i, i)].. " ")
else
write(string.sub(input, i, i))
end
end
else
for match in input:gmatch("[^ \t]+") do
if bTranslations[match] then
write(bTranslations[match])
else
write(match)
end
end
end
print() --Make another line
end
I didn't have much time so you can type "1" to translate number to binary, and "2" for vice versa.