« Back to the Da Slop Pit Forum

Small file hasher written in hare

Posted by Dio9sys

posted
updated

Forum: Da Slop Pit Group

Hi :)

I wrote a quick file hasher in hare.  Run the program and pass whatever file you want hashed as an argument and it'll make the sha256 hash for it and print it out for you <3

 use crypto::sha256;
 use encoding::hex;
 use hash;
 use io;
 use os;
 use fmt;

 export fn main() void = {
     const hash = sha256::sha256();
     const file = os::open(os::args[1])!;
     io::copy(&hash, file)!;

     let sum: [sha256::SIZE]u8 = [0...];
     hash::sum(&hash, sum);
     hex::encode(os::stdout, sum)!;
     fmt::println()!;
};

Save this file as hash.ha, install the hare compiler and standard library and then compile by running hare build -o hash hash.ha in the same directory.  Then you can run ./hash [file] to get the hash <3

Be careful!  If you don't add a file as an argument then you get a core dump from the array being out of bounds!  :0


Report Topic

2 Replies

Sort Replies:

Reply by VVX7

posted

Thank you for your service 7o


Report Reply

Reply by Dio9sys

posted

NOTE!!!!

This is pared down and edited from one of the example files on the hare documentation.  I forgot to mention that, but I really just trimmed down a few lines and made it accept arguments instead of using a known file <3


Report Reply