? SHA-1 Hash Function ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
[Help Wanted] SmileBASIC Documentation Project

SHA-1 Hash Function

Submitted
Updated
Author
MasterR3C0RD
Public Key
CDDNV3LJ
Min. Compat.
All
Rating
4 votes
Description 747 hashes per second on N3DS! Take that, SHA-256! Instructions DEF SHA1 ARR, ML OUT N1, N2, N3, N4, N5 ARR = Array of bytes ML = Length of ARR N1-N5 = Final block states O3DS results: 190 hashes/sec N3DS results: 747 hashes/sec Notes Note that SHA-1 is no longer secure, and should not be used for anything important. Don't hash passwords with this. You'll regret it.
Categories
Keywords
17 Comment(s) Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies Awesome! Really fast! MasterR3C0RD MasterR3C0RD Helper Received for being very helpful around SmileBASIC Source Achievements Third Year My account is over 3 years old Website osu! Is Awesome! I love osu! Express Yourself I was surprised when I had someone in chat run it and get nearly 750 hashes/sec. I assume it's all thanks to not using functions as much as anything else (that really made a difference in performance), the fact that SHA-1 is relatively basic and fast anyways, and not having the HEX$ logic inside of the function. I think there may be problems with strings above 64 bytes though, but I'm not sure. Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies It's still really fast if you put the string-to-array conversion inside the test, 630 hashes/sec I'm gonna try updating SHA256 MasterR3C0RD MasterR3C0RD Helper Received for being very helpful around SmileBASIC Source Achievements Third Year My account is over 3 years old Website osu! Is Awesome! I love osu! Express Yourself Honestly, it'd be really really interesting if a method of (ab)using ARYOP could make this go even faster, but I think I already talked to 12 and he said it wasn't possible. Good luck updating your library though, SHA-256 is a lot better than SHA-1 lol 12Me21 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Yeah ARYOP only does floating point operations Bit shifts are REALLY difficult but they can be done with multiplication/division Other bitwise operations are impossible, though you can use + instead of OR if none of the bits overlap. Even addition will cause problems because you'll have to do bounds checking MasterR3C0RD MasterR3C0RD Helper Received for being very helpful around SmileBASIC Source Achievements Third Year My account is over 3 years old Website osu! Is Awesome! I love osu! Express Yourself ARYOP has #AOPCLP though, would that not work for boundchecking? #AOPCLP Clamping (Rounding the value of p1 to the range of p2<=x<=p3) 12Me21 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself It has to overflow/underflow properly though. It's definitely possible but you'd need like 4 ARYOPs per addition Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies I think it's possible, since bitwise operations have mathematical equivalents, the whole overflow/underflow thing could be done by having multiple arrays of the same values, keep one as is, subtract/add 0xFFFFFFFF for two, subtract/add 0xFFFFFFFF*2 for two others... and so on, then you'll have tons of arrays Then do some max/min tricks to select the values closest to zero, that would work, right? The mathematical equivalents of bitwise operations is a bit more difficult... but even then (although unrealistic), theres the possibility of multiplying/dividing by powers of 2 in order to get every bit by itself in different arrays, then those operations can be done with ease. It's too much work in my opinion, and has the possibility of running out of memory DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength I made this function. I don't know what is does lol: DEF FSHA1(N%) VAR NUMS%[4] NUMS%[0] = (N% AND &HFF) XOR N% NUMS%[1] = (N% AND &HFF00) XOR N% NUMS%[2] = (N% AND &HFF0000) XOR N% NUMS%[3] = (N% AND &HFF000000) XOR N% RETURN “&H”+HEX$(NUMS%[0])+HEX$(NUMS%[1])+HEX$(NUMS%[2])+HEX$(NUMS%[3]) END DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength I never used XOR so.... MasterR3C0RD MasterR3C0RD Helper Received for being very helpful around SmileBASIC Source Achievements Third Year My account is over 3 years old Website osu! Is Awesome! I love osu! Express Yourself It'll just output the input XOR'd with itself for some parts, and output itself for others. X XOR X = 0 and 0 XOR X = X, so this is not useful at all. SHA-1, on the other hand, leverages a lot of different ideas and mechanics in order to do things like the avalanche effect. Making a toy cryptographic function, in my opinion, is a great way to practice things like reversible and irreversible transformations. If you're wanting to keep data safe, however, depending on things that aren't made by cryptographers is a terrible idea, and you will 100% regret it. Shelly Shelly You might be thinking of XOR encryption, which is something like this (excuse my sloppy code): DEF ENCRYPT(MSG$,PASSWORD$) KEY$=PASSWORD$ REPEAT PUSH KEY$,PASSWORD$ UNTIL LEN(KEY$)==LEN(MSG$) OR LEN(KEY$)+LEN(PASSWORD$)>LEN(MSG$) FOR I=0 TO LEN(MSG$)-LEN(KEY$)-1 PUSH KEY$,PASSWORD$[I] NEXT RETURN MSG$ XOR KEY$ END The exact implementation varies, but basically it works like this: Let's say we have a number that we want to make secret, so only certain people can view it. For this example I'll use the number 3. 0011 Then, we need to pick a password. I'll choose 1. 0001 Now we just XOR the two. 0011 0001 0010 Notice if we have the password we can easily view the original number by XORing the password with the created message. The code I wrote is a bad example, but the explanation should give you a general idea. Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies Yeah, like MasterR3C0RD said, you can instantly figure out the password by "encrypting" 0000 with XOR: 0000 0001 (secret password) =0001 If you XOR-encrypt a bunch of whitespace or repeating characters then anyone can do a bit of cryptanalysis to figure out the password. What makes SHA algorithms secure is the fact that 32 bits of the message are fed into the hash every round, slower than it get scrambled, so the scrambling takes over. For SHA-2, any bit of the output is dependent upon every single bit of the input, it's just a huge mess of XORs and ANDs and ORs and NOTs and zero-fill right shifts. Shelly Shelly Wouldn't figuring out the password require that you have the original message, or the length of the password? If you just had the created string then you would just have seemingly random data. Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies A strong cipher needs both substitution and transposition, XORing is only substitution so it's susceptible to frequency analysis. Chances are there's whitespace in an "encrypted" file, which would look like repeating symbols, take the repeating symbols in binary and XOR them with a bunch of whitespace in binary, to get the repeating password in binary, then you just need to know where that password starts and ends within those repeating bits. For XOR you only need two of the three values before you can compute the unknown value with certainty. In this case the cipher is one of the values, and the input we think it is, is the second value. Shelly Shelly Is N1 the least significant part or most significant part? 12Me21 12Me21 Head Admin Second Year My account is over 2 years old Website Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself most significant (ew)