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

Converting key input into ASCII numerals

Started by TheQuack45, 01 March 2014 - 09:42 PM
TheQuack45 #1
Posted 01 March 2014 - 10:42 PM
I am looking into creating an "encryption" (it is closer to a one-way hash system) system used so that data can be transferred over rednet, etc. in non-plaintext form, as well as other situations where non-plaintext would be necessary/preferred.

Because I don't know how to set up MD5 hashing (not sure how to create my own lua hasher and I don't think the http API would be useful here), I'm instead creating my own "hasher" (again, not really a hasher) that works as follows (in the context of a password program):

Inputted characters are converted to their ASCII numerical forms (codes 32-127) and the numerical values are added up. The resulting value is then put through a number of mathematical operations and finally compared to a pre-hashed value stored in the program (which is the stored password); if they match, the correct password was entered. If they do not match, an incorrect password was entered.

I know, the fact that the hashing process is stored in the program makes this somewhat easy to crack, but I'm doing it for the hell of it.

Are there any fast/easy ways to do this? I know I could do it through a ton of if statements, but that is incredibly slow, inefficient, and not ideal. A switch statement (are those in Lua? I'm coming from Java) could also work and be slightly faster, but still quite bad.

Thanks!
Thib0704 #2
Posted 02 March 2014 - 12:56 AM
Why don't you use GravityScore's modified SHA256 function?
http://www.computercraft.info/forums2/index.php?/topic/8169-sha-256-in-pure-lua/
TheQuack45 #3
Posted 02 March 2014 - 02:42 AM
Why don't you use GravityScore's modified SHA256 function?
http://www.computerc...56-in-pure-lua/

Ah, didn't see this! Thanks, will look into it.