Posted 03 April 2016 - 08:15 PM
I have been trying to make an API to encrypt/decrypt text. Everything was running smoothly, until I tried adding more characters to the list.
Suddenly, I am receiving an error:
Suddenly, I am receiving an error:
I have checked this multiple times, and I am closing the table. My code:bios: 339: [string "crypto"]:19: '}' expected (to close '{' at line 9)
-- crypto API
-- Encryption software for ComputerCraft
---------------------------------------------------
-- Functions:
-- crypto.toBinary(text)
function toBinary (text)
local binary = ""
local charList = {"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", "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", " ", ".", ",", "!", "?", "'", "-", "_",
"1", "2", "3", "4", "5", "6", "7", "8", "9",
"0", "@", "#", "$", "%", "^", "&", "*", "=",
"+", "-", "/", "(", ")", "[", "]", "{", "}",
"<", ">", """, "'", ":", ";"}
for i = 0, string.len(text) do
for j = 0, table.getn(charList) do
if string.char(string.byte(text, i)) == charList[j] then
local num = j
if num >= 64 then
binNum = "1"
num = num - 64
else
binNum = "0"
end
if num >= 32 then
binNum = binNum.."1"
num = num - 16
else
binNum = binNum.."0"
end
if num >= 16 then
binNum = binNum.."1"
num = num - 16
else
binNum = binNum.."0"
end
if num >= 8 then
binNum = binNum.."1"
num = num - 8
else
binNum = binNum.."0"
end
if num >= 4 then
binNum = binNum.."1"
num = num - 4
else
binNum = binNum.."0"
end
if num >= 2 then
binNum = binNum.."1"
num = num - 2
else
binNum = binNum.."0"
end
if num >= 1 then
binNum = binNum.."1"
else
binNum = binNum.."0"
end
binary = binary..binNum
end
end
end
return binary
end