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

encryption

Started by wilcomega, 01 October 2012 - 05:55 PM
wilcomega #1
Posted 01 October 2012 - 07:55 PM
i saw some encryption programs for lua on lua-users.org but they all require external C libraries. and i dont think CC can load those guys.
so if anyone has an encryption and decryption api ready or know one (with passwords) then i would like to use it!

thx in advance :)/>/>
wilcomega
GopherAtl #2
Posted 01 October 2012 - 08:12 PM
tomas1996's StringUtils includes some password-based encryption/decryption I think? It' a bit outdated now - some of it's functions are in the native stringutils library, and it's lua-based bitwise operations ought to be removed and the algos written to use the java-based ones in the new java-based bitwise api for cc 1.42+, but it's still usable as-is I assume. Not tried the encryption, only used the SHA1 function, but it worked well enough.

Link to his thread here http://www.computercraft.info/forums2/index.php?/topic/42-cc13string-utils-api/
Cranium #3
Posted 01 October 2012 - 09:04 PM
What would be the application of this encryption? If it's simple, like a keycard system, you can use math.randomseed() to do a little jiggery… I'll come up with something a little easier to look at than just ideas soon…
Cranium #4
Posted 01 October 2012 - 09:38 PM
Strike that…I know nothing of what I am talking about….. Using math.randomseed() is super difficult to implement. Using someone else's pseudo-random number generator is not really a good idea.
jag #5
Posted 01 October 2012 - 11:18 PM
Found a way: Hz5zR22t
MysticT #6
Posted 01 October 2012 - 11:29 PM
Found a way: Hz5zR22t
Well, it would be better to use a simple xor encryption:

local function xorEncrypt(data, key)
    local klen = #key
    local s = ""
    for i = 1, #data do
        s = s..string.char(bit.bxor(string.byte(data, i), string.byte(key, i % klen)))
    end
    return s
end
The same function works to encrypt and decrypt.
Cranium #7
Posted 01 October 2012 - 11:32 PM
That's more of a cipher than a true encryption… isn't it?
MysticT #8
Posted 01 October 2012 - 11:33 PM
That's more of a cipher than a true encryption… isn't it?
Cipher = program that encrypts. :)/>/>
It's not a good algorithm and it's easy to break, but should be enough for most CC uses.
Cranium #9
Posted 01 October 2012 - 11:41 PM
Meh, I suppose.
Gonna try to implement this into some sort of keycard system.
PixelToast #10
Posted 02 October 2012 - 12:13 AM
i made a super secure one here
jag #11
Posted 02 October 2012 - 12:40 AM
Found a way: Hz5zR22t
Well, it would be better to use a simple xor encryption:

local function xorEncrypt(data, key)
	local klen = #key
	local s = ""
	for i = 1, #data do
		s = s..string.char(bit.bxor(string.byte(data, i), string.byte(key, i % klen)))
	end
	return s
end
The same function works to encrypt and decrypt.
Well, I don't know anything about encrypting, I just fount that on the interwebs
Cranium #12
Posted 02 October 2012 - 12:48 AM
Well, I don't know anything about encrypting, I just fount that on the interwebs
Hooray for Google!!!
jag #13
Posted 02 October 2012 - 12:51 AM
Hooray for Google!!!
Google is your friend! (Not Yahoo or Bing!!)
:)/>/>