Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function connect(modem,AUTH_CHANNEL,BigNum)
- local prime = BigNum.new("625210769")
- local base = BigNum.new("11")
- local secret = BigNum.new(math.random(1,1000))
- local event = {}
- local PING_PORT = 1
- local KEY_EXCHANGE_PORT = 2
- local order
- local _, mySecret = (base^secret)/prime
- local hisSecret
- modem.open(AUTH_CHANNEL)
- modem.transmit(AUTH_CHANNEL,PING_PORT,"ping")
- while true do
- event = {os.pullEvent()}
- --event, side, frequency, replyFrequency, message, distance
- if event[1] == "modem_message" and event[4] == PING_PORT then
- if event[5] == "ping" then
- order = 2
- modem.transmit(AUTH_CHANNEL,1,"pong")
- break
- elseif event[5] == "pong" then
- order = 1
- break
- end
- end
- end
- if order == 1 then
- modem.transmit(AUTH_CHANNEL,KEY_EXCHANGE_PORT,mySecret)
- repeat
- event = {os.pullEvent()}
- until event[1] == "modem_message" and event[4] == KEY_EXCHANGE_PORT
- hisSecret = event[5]
- elseif order == 2 then
- repeat
- event = {os.pullEvent()}
- until event[1] == "modem_message" and event[4] == KEY_EXCHANGE_PORT
- hisSecret = event[5]
- modem.transmit(AUTH_CHANNEL,KEY_EXCHANGE_PORT,mySecret)
- end
- local _,v = (hisSecret^secret)/prime
- return v, order
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement