A hash function is a mathematical algorithm that converts large data into a small fixed-size number, where the same input always produces the same output, making it useful for detecting data changes and verifying file integrity; in Go, the hash/fnv package provides the FNV-64 hash function, which implements the hash.Hash64 interface (extending hash.Hash and io.Writer) to compute checksums for files, allowing developers to verify file integrity by comparing hash values before and after file modifications.
How to Compute File Checksums in Go: FNV and MD5 Hash Tutorial
Added:okay so before we move on to our life for a final language topping which is concurrency during the deal on be clear program which we can use as an example for later and that program is this problem about finding the m5 check some of a file I think we know enough to do this but I want to walk through something very similar so that be quickly so tech sound is taking some big huge chunk of data and turning it into a small number and we use that because number of lot easier to work with in this huge Flocka date and we can use it for example if I take the check some of the same block of data I get the same number in the end and so then I can know the file has of change for gym because if it changes then the check some changes that's the idea of which text comes forward okay and so we are going to do one that's not any five and then you can use em provider as your example so what I'm going to use is one called FNB okay FNB is named daddy committed and it's in hash / fnv so the general I gave you those things are called I hacks they take big things and make them into a small number and they do so so that the same big thing ends up with the same room okay this is called non cryptographic hash so think about a 50 graphic hashes it means it's hard to go the other direction I can't take that number and know what files will do sir okay it's hard for me to like all I have this number and figure out how to make a file that produces that number that's an important property for certain this one's not cooking right what that means is it doesn't have that property am I gonna catch I can figure out of it we don't need to worry about that so much the point is this one is very simple it is also a hash md5 hash so using the same way to give you a different number two silver so we're going to use this and what we want to do is create a program which takes the file and gives us that hash it computes the fnd hash of that file remember we did the md5 hash for the gravatar goes in punjab okay so i'm going to write that program real quick i'm going to call it f NV some new file ain't never package and it's going to start very similar to this one we're going to open a file except this one will come from the user you guys remember how to do that no RX one and now i'm going to create a hatch so the way this works is you say FNV news 64 or new 64a doesn't so I'm going to say that new 64 that returns a hash 64 so it's imaginable so go look at that 54 you can see what that is before is an interface okay it has one method even 64 and it has hatched so I did not describe these when I talk about anything but when you in bed remember how I'm betting we can invent types and Android and edit person and I can call any methods that are person on Henry this is very similar with an interface I embedded another interface inside of it and basically what that means is a 64 is some 64 method plus everything that hash contains so if we go look at hash so it also includes all of these right includes block sighs sighs we set some and notice it also includes right writers and other interface when we've been using so what this means is that ash has a right method because hash is a right way right an ass explores a hat so hack 64 is ash which is a writer so passionate supporters also a right what that is its ability to do is I can usually can copy so I'm going to call it h co niqua new 64 i'm going to say hi or copy but H is the writer and they readers the file okay and then I'm going to return or not return here print it out h dot some give it nil okay so what this does is that hash function it takes a bunch of data and it reads it and then it gives you a number again that's all the new here is you can give it some data the other thing we could do instead of some is we could say 64 and that will give us that number as an integer we do some it gives it as a slice of ice because these very sad functions can give different sizes of that number like some are this one is a 64 bit but md5 is a hundred twenty years old it's um it's a different number of kids and so that's the sum is more generous okay so if we print that we should get the FNB hash of a fire so here that go install and then I'm going to compute it a vote of this name so that's the hash okay so let me make a change to the file you scratch that a very similar it's good version one thank you all I'm going to do is say the Sun is so now I'm going to print out the Sun is and the reason I'm doing that is what I'm changing this file by changing this file when I rerun this program so I'm going to go install and then run this program again I get a different number okay so anytime one bite of that cloud changes you get a different number that's the point of the hatch ok so the hash would be like a stand-in for the version of the fire or something like that it's very useful thing to happen because like I said it's a very huge amount of data it makes it a very small type and I you compare numbers easily by comparing to five of us is heart I actually like repo so it's a useful thing to have and like i said is also useful thing for verifying that your climate change right because i can get a file and that number and then at the end i can go check it it's a big file downloading I can check it against the Snowbird I can run the same entities up on that same vibe if the numbers match that means it didn't change and so I can be I can be sure that I got the right file and you actually do see that the floor tiles people often attached to them that empty file we're doing am going to be number but the prime example going to do is with an mp5 but the same basic value I'm pretty following what we're trying to do here you know ok so our problem is to take this basic template and make one that uses md5 instead of the FN v ok write this as create a program which finds the md5 checksum up a file I want to be able to say my mp5 filing and get this kind of number ok everyone cool dude on the curly head up there was a big change I was copying change something roots just like gee I just added an extra text
Up Next

Go Mutexes Explained: Preventing Race Conditions in Concurrent Programming
@TheCodingGopher
335 views•2024-10-06

Introduction to Secure Multiparty Computation with Yehuda Lindell
@fhe_org
7.7K views•2021-02-04

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science









![[Tucker의 Go 언어 프로그래밍] 21장 함수고급편](https://i.ytimg.com/vi/qRyHepiTEs8/maxresdefault.jpg)





























