392 posts
Location
Christchurch, New Zealand
Posted 13 January 2013 - 09:18 PM
Hello CC Forums,
Just bringing you another API, it's the RC4 encryption algorithm re implemented for ComputerCraft, RC4 is a fast stream algorithm and is used in protocols like SSL and WEP.
Download Link:
http://pastebin.com/rDUe5wGeSpoiler
Create an encryption session:
enc = rc4.new("my secret key", true)
Create a decryption session:
dec = rc4.new("my secret key", false)
Encrypt some text for transmission:
secretText = enc.encrypt("Psst, Lua is cool!")
Decrypt the text at the other end
plainText = dec.decrypt(secretText)Each time you encrypt something, the internal state changes, so you have to decrypt the same amount of data as you encrypt for the sessions to stay in sync, Meaning that if you encrypt two messages, you need to decrypt both messages otherwise the decryption stream wont have the same key state as the encryption.
I'm not very good with documentation. So please just leave any comments here and I'll help the best I can. Thanks
139 posts
Location
USA
Posted 13 January 2013 - 11:09 PM
Sounds cool. I'll probably never use it but I always like seeing people do things like this :P/>
392 posts
Location
Christchurch, New Zealand
Posted 14 January 2013 - 09:06 AM
Thanks :)/>
The API's I typically post don't seem to get a lot of attention as they're normally technical and only have cliche use. But this would be good for anyone making an OS or some networking software. It'd be good to see some real encryption being used by some of the CC devs. :)/>
5 posts
Location
Germany
Posted 16 January 2013 - 08:12 AM
Line 64 : "}" missing.
392 posts
Location
Christchurch, New Zealand
Posted 16 January 2013 - 08:15 AM
Line 64 : "}" missing.
Excellent spotting, not sure how that character got away. Thanks.
Link fixed.
7508 posts
Location
Australia
Posted 18 February 2013 - 07:30 PM
Oh noes, I'm grave digging :(/>
How did I not see this earlier! Gotta love search ;)/>
Just posting to say, 'tis awesome and needs to be used by people a lot more, and I'm gunna use it in my messenger program :)/>
392 posts
Location
Christchurch, New Zealand
Posted 18 February 2013 - 07:31 PM
Thanks TOBIT :D/>
Yeah, it never really took off, Kinda just let it rot :)/>
799 posts
Location
Land of Meh
Posted 18 February 2013 - 08:35 PM
YES! I wanted an RSA or RC algorithm to use to encrypt Rednet messages! :D/>
Mind if I use this to encrypt sent messages in Firewolf? :P/>
7508 posts
Location
Australia
Posted 18 February 2013 - 08:40 PM
YES! I wanted an RSA or RC algorithm to use to encrypt Rednet messages! :D/>
Well I guess it was a good thing I bumped it :P/>
EDIT: So tell me NeverCast. Is this KSA, PRGA, or some variant?
Edited on 18 February 2013 - 07:44 PM
392 posts
Location
Christchurch, New Zealand
Posted 18 February 2013 - 08:43 PM
This api is free to use :)/>
I'd love to see it actually in use :D/>
WOO!
137 posts
Location
the Netherlands
Posted 22 February 2013 - 12:37 AM
AFAIK, rednet doesn't support characters higher than 127 very well.
Would this still work if I replaced all '256' for '128' ?
392 posts
Location
Christchurch, New Zealand
Posted 24 February 2013 - 10:40 PM
Yes that would work. I assume you're meaning with RedPower cables. Which are being retired from CC.
392 posts
Location
Christchurch, New Zealand
Posted 24 February 2013 - 10:42 PM
So tell me NeverCast. Is this KSA, PRGA, or some variant?
Uhh.. They're both required for RC4. So both.
808 posts
Posted 27 February 2013 - 08:15 PM
I'll be honest Nevercast, your content is some of my favorite on the forums.
1029 posts
Location
Missouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension
Posted 17 May 2013 - 11:14 PM
Umm, the commands don't work…
7 posts
Posted 31 July 2013 - 09:02 PM
I just came across this and, I'm impressed. I hope you don't mind if I use this to add some encryption to my accounts API (credit to you of course)
Edit: oops I revived something ;)/>
2217 posts
Location
3232235883
Posted 31 July 2013 - 09:06 PM
verry nice, you can increase the efficiency of the encryption and key generation alot though
2217 posts
Location
3232235883
Posted 01 August 2013 - 03:13 PM
just realized, this lacks public / private asymmetric key generation, atm its just symmetric encryption though i dont see a good way to generate large primes :/
might be vulnerable to plaintext attacks, but its more secure than what ive got
sorry for doublepost, wanted to bump
131 posts
Posted 09 August 2013 - 03:23 PM
RC4 is a symmetric stream cipher. The key generation / exchange is up to you.
Do yourself a favor and discard the first 256-4096 bytes. Information about the key can be derived from the first bytes of the keystream.
Also, if you use a salt in your key-exchange, XOR it with the key or hash them concatenated to get the final key. Don't concatenate them and directly use that as the cipher's input.
Or you could wait until tomorrow afternoon when I add a more secure RC4 variant to
my version.
2217 posts
Location
3232235883
Posted 09 August 2013 - 06:35 PM
RC4 is a symmetric stream cipher. The key generation / exchange is up to you.
o_O the topic was changed from RSA, derpy me
7508 posts
Location
Australia
Posted 10 August 2013 - 04:20 AM
i dont see a good way to generate large primes :/
KillaVanilla seemed to do it fine in his security protocol implementation…
o_O the topic was changed from RSA, derpy me
o.O It has always been RC4…………….
2217 posts
Location
3232235883
Posted 10 August 2013 - 12:33 PM
im pretty sure it was RSA before, idk
34 posts
Location
United States
Posted 14 August 2013 - 11:50 AM
I doesn't seem to be working. It return question marks because it tries to uses unknown characters.
2217 posts
Location
3232235883
Posted 14 August 2013 - 12:29 PM
I doesn't seem to be working. It return question marks because it tries to uses unknown characters.
nope
it works fine, (other than breaking after 255 chars because he is using modulo wrong c_c)
131 posts
Posted 17 August 2013 - 05:56 PM
I doesn't seem to be working. It return question marks because it tries to uses unknown characters.
nope
it works fine, (other than breaking after 255 chars because he is using modulo wrong c_c)
Hey, would you check
my implementation for that error?
I'm pretty sure it works for large data, but it would help to get independent verification.
2217 posts
Location
3232235883
Posted 17 August 2013 - 09:19 PM
i already tested it, its fine and is also significantly more efficient (200%) when encrypting large amounts of data
7508 posts
Location
Australia
Posted 18 August 2013 - 01:53 AM
is also significantly more efficient (200%)
Supply proof, or else people will think you've just made up that number.
2217 posts
Location
3232235883
Posted 18 August 2013 - 02:54 PM
i tested it with a couple os.time tests
c_c
even after my tweaks to nevercatsts to reduce function calls and fix the overflow error it took seconds to encrypt a huge amount of data
and agents took around 0.5 seconds on average
its mostly due to the fact that nevercast uses the key state table in an awkward way and he was swapping indices correctly:
local t=stuff1
stuff1=stuff2
stuff2=t
while agent did this:
stuff1,stuff2=stuff2,stuff1
i dont remember exactly what most of the results were (and i dont have the time to test it for you)
and i dont see why i had to supply proof, i said i tested it
7508 posts
Location
Australia
Posted 18 August 2013 - 03:41 PM
and i dont see why i had to supply proof, i said i tested it
Because you magically pulled "200%" out of the air… And it is important that people see how numbers are calculated otherwise it could just be bias data/info…
Would you believe me if i told you that my computer was 158.746% more efficient than yours?
2217 posts
Location
3232235883
Posted 18 August 2013 - 03:46 PM
i did not pull 200% out of the air, that was on average how fast it completed (iirc results from 0.6-1 and 3-5) .-. i tested it, its more of a credibility issue
i would not believe your computer was more efficient because you dont have my computer at your disposal and efficiency dosent have a constant ratio for computers, that is a different thing entirely
a better example would be something like screen size (i know mine is smaller), though a lot of people posted in the post your desktop thread
392 posts
Location
Christchurch, New Zealand
Posted 21 August 2013 - 12:59 AM
Pixel, What are the issues in my script, I'll amend them :)/>
I'm glad it works with large data, I think that was the intention anyway.
1847 posts
Location
/home/dannysmc95
Posted 11 March 2016 - 11:08 AM
I love this very much and I plan to use it in a new update, my only question is there anyway to fix the 245 character limit? I did testing and anything over 245 characters will break the encryption… Have you got any way to fix this? Thanks (Sorry for the necro)
Edited on 11 March 2016 - 10:08 AM