Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local channel = 1
- local prime = 625210769
- local primeRoot = 11
- m = peripheral.wrap("top")
- m.open(1)
- function baseToPowerMod(base,power,modulus)
- --This function was taken from Anavrins' Diffie-Hellman proof of concept
- --Full code here:http://pastebin.com/H3kZHZBA
- local remainder = base
- for i = 1, power-1 do
- remainder = remainder * remainder
- if remainder >= modulus then
- remainder = remainder % modulus
- end
- end
- return remainder
- end
- print("Calculating secret number...")
- local secretNum = math.random(100,999)
- print("Done")
- print("Calculating public key...")
- local public = baseToPowerMod(primeRoot,secretNum,prime)
- print("Done")
- print()
- print("Secret Number:"..secretNum)
- print("Public Calc:"..public)
- print()
- print("Waiting for other computer...")
- m.transmit(1,os.getComputerID(),{"sec","publicNum",public})
- while true do
- local event,p1,p2,p3,p4,p5 = os.pullEvent("modem_message")
- if type(p4) == "table" and p4[1] == "sec" and p4[2] == "publicNum" then
- m.transmit(1,os.getComputerID(),{"sec","publicNum",public})
- print("Recieved public key from Computer ID "..p3)
- local sharedNum = baseToPowerMod(p4[3],secretNum,prime)
- print("Shared number:"..sharedNum)
- break
- end
- end
- m.closeAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement