Posted 11 June 2014 - 07:17 PM
I am writing a bank server/client for my server, but it keeps throwing this error: 40:'<eof>' expected. I'm pretty sure that that means I have one too many ends, but cant figure out where it is. Please Help!
Spoiler
os.loadAPI("StrUtils")
rednet.open("top")
wire = peripheral.wrap("right")
wire.open(1)
num1=0 --Key Prime Number
num2=0 --Key Power Number
num3=0 --Key Secret Key
num4=0 --Key Public Self
num5=0 --Key Public Client
key=0 --Encryption Key
cpin=0 --Current User
cid=0 --Current User
function rednetWait(uid,mess)
while true do
local id,message = rednet.receive()
if uid == id then
if mess == message then
break
end
end
end
end
function isPrime(x)
if x%3 == 0 then
return false
else
local f = 5;
while f <= math.floor(x^0.5) do
if (x%f) == 0 then return false end
if (x%(f+2)) == 0 then return false end
f = f + 6;
end
end
end
return true
end
function agreeNums(id)
num1=4
while !isPrime(num1) do
num1=math.random(0000,9999)
end
rednet.send(id,"p"..num1)
rednetWait(id,"power")
num2 = math.random(0000,9999)
rednet.send(id,"m"..num2)
rednetWait(id,"next")
end
function keyExchange(uid)
agreeNums(uid)
num3 = math.random(99999999999999999999999999)
num4 = (num2 ^ num3) % num1
rednet.send(uid,"l"..num4)
while true do
local id,message = rednet.receive()
if uid == id then
if message:sub(1,1) == "K" then
break
end
end
end
num5=message:sub(2,-1)
key=(num5 ^ num3) % num1
end
function recMes(mess,id)
if mess == "keyx" then
if cid == id then
keyExchange(id)
end
end
local mess = StrUtils.decrypt(mess,key)
local messC = mess:sub(1,4)
if cid == 0 then
if messC == "logn" then
wire.transmit(1,1,"L"..mess:sub(5,-1))
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
if message == "S" then
cpin = mess:sub(5,8)
cid = id
rednet.send(id,StrUtils.encrypt("S",key))
else
rednet.send(id,StrUtils.encrypt("EBad Login",key))
end
end
end
if ccid == id then
if messC == "newu" then
local pin = math.random(1000,9999)
rednet.send(id, StrUtils.encrypt("["..pin, key))
wire.transmit(1,1,"+"..pin..mess:sub(5,-1))
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
if message == "S" then
cpin = pin
rednet.send(id,"S")
else
rednet.send(id,"E")
end
elseif messC == "sync" then
local hash = StrUtils.SHA1(cpin..cid..key)
if mess:sub(5,-1) == hash then
rednet.send(id,StrUtils.encrypt("S",key))
else
rednet.send(id,StrUtils.encrypt("EError in Authenticating",key))
cpin=0
cid=0
key=0
end
elseif messC == "tran" then
wire.transmit(1,1,"T"..mess:sub(5,-1)
rednet.send(id,StrUtils.encrypt("S",key))
elseif messC == "bala" then
wire.transmit(1,1,"B"..cpin)
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
rednet.send(id,StrUtils.encrypt("B"..message,key))
elseif messC == "logo" then
cpin=0
cid=0
key=0
end
end
end
function main()
while true do
id,message = rednet.receive()
recMess(message,id)
end
end