--[[ Diffie–Hellman key exchange in a simple to use library Note: this does NOT use big integers this is designed for computercraft's limited processing power use a Diffie–Hellman key exchange algorithm that can handle big integers for real-world applications --]] local n= 625210769 local g= 11 local secret = 0 local 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 function createSecret() -- returns public key to send to partner secret = math.random(1000,9999) local public = baseToPowerMod(g,secret,n) return public end function handshake(public) -- returns key to use for symmetric encryption if secret == 0 then error("Secret as not been created",2) end local key =baseToPowerMod(public,secret,n) return key end function getDoc() return [[createSecret(): returns public number to send to partner handshake(int public): returns key to use in symmetric encryption]] end