This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Piorjade's profile picture

True Encrypted Chat (no name found lul)

Started by Piorjade, 10 August 2017 - 05:24 PM
Piorjade #1
Posted 10 August 2017 - 07:24 PM
I was pretty bored and as this community is slowly dying I don't have the motivation to update cLinux…

So while I was watching videos on how encrypting messages works I figured it would be a fun idea to remake my encrypted chat program for CC.

Soo this one uses the Diffie-Hellman-Merkle key exchange and the AES Encryption API by SquidDev to encrypt and send messages.

It has to establish a connection first though, because that's how the key exchange works for me.

(In case you were wondering, I used X^(Y%P) as the formula to calculate the encryption key (well that's the formula I took from a video about encryption lol) where Y and P is a set value I random typed (it is supposed to be known by everyone) and X is generated on runtime (it is a value between 1 and 10^13). X doesn't get exchanged but is later used to generate the actual encryption key…)

Here's the link to the pastebin:
Click

Btw there might be bugs with the UI and there's no checking if the connection to the other user is lost other then printing "**exited**" when the other user enters the /exit command…
LDDestroier #2
Posted 14 August 2017 - 06:34 AM
Tried it out on CCEmuRedux. Pretty good. I made an encrypted chat program too, but mine uses a string key, whereas your's is dependent on the computer ID. Keep up development, and I might consider it a competitor to my Enchat. not
Piorjade #3
Posted 15 August 2017 - 07:12 PM
The key isn't dependent on the computer ID at all. The key is actually a randomly picked (big) number which gets converted to a string to encrypt the messages. The key gets calculated after you established a connection to somebody.

You only need to enter the computer ID so that the program knows how to connect to (so that they can calculate the actual encryption key blablabla).


Tbh I tried to make a RSA "email-system" but I realized that LUA can't keep up with big modulo calculations so I gave up…
The Crazy Phoenix #4
Posted 22 August 2017 - 05:15 AM
Lua can handle big modulo calculations with an efficient algorithm. There's a fairly simple algorithm in O(log n), compared to the "subtract modulus until less than modulus" algorithm in O(n).

Namely, that algorithm involves using the binary decomposition of the operand. Here's some pseudocode.


function modulo(n, m)
	p = {m}
	while p[#p] < n do
		p[#p + 1] = 2 * p[#p]
	end
	while n < m do
		p[#p] = nil
		if n > p[#p] then
			n = n - p[#p]
		end
	end
	return n
end

Naturally, you're free to come up with your own algorithm.
Edited on 22 August 2017 - 03:17 AM