Jump to content

sum of hash [solved]


Recommended Posts

I've got a bunch of hash from files in a folder

0x45B265C13EC41DD3272E547A837EF0604E06EF6C
0x73418EE0D435F0995DE000A0CB9A895B8031D62B
0x6FB325DDFA9AFCB148B815F41C94F5BBC3735E0B
0xE8BC5E1676E64E9EE77A7EBD56D910D60D453A2A
0xFF311E2FEC610B2E0A3169435CBC48D5B1B53A57
0x728EDF8577DF247CBC69ED6F2F9EACB3BF845150
0x8CABC5A4BDA856E0D0E884D0F4A335CB2457941D
0xCEBB04B9099141009329E13EDBD8B5CFB14A49A5
0xD7AA968FCF6AC9691F6ED801BA9291EBBBAFED71
0xBBBA76A66C54D53BADE77245D9F205F1EB9CC685
0x39DD14E5DB99F39F68182494C0B48CEFB5DDFDDF
0x32C2A01B523D973D933FC004237CAB4B792231BF
0x6AE1A10B7505DDABEECEAFD13B2EC2A8D7286587

how can I make a sum of the hash to have a hash that'd represent these hash as a single hash resultant of these ?.
I was thinking of sorting them and adding 'em to a string and hash that string but there may be a proper way to do it.
Any and all ideas are welcomed.

Edited by argumentum
edit title / solved

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

1 minute ago, TheDcoder said:

Not sure if its possible :unsure:...

in Func _Crypt_HashData($vData, $iALG_ID, $fFinal = True, $hCryptHash = 0) it shows that you can continue adding strings, continuing on a prior string, that in itself should have a hash. It should be possible. I just don't know how.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Where does the hash data come from?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hello. This is a simple idea. (it does not mean that it is strictly correct.)

 

#include <Crypt.au3>
#include <Array.au3>

Local $aHashes1[] = ["0x45B265C13EC41DD3272E547A837EF0604E06EF6C", _
        "0x73418EE0D435F0995DE000A0CB9A895B8031D62B", _
        "0x6FB325DDFA9AFCB148B815F41C94F5BBC3735E0B", _
        "0xE8BC5E1676E64E9EE77A7EBD56D910D60D453A2A", _
        "0xFF311E2FEC610B2E0A3169435CBC48D5B1B53A57", _
        "0x728EDF8577DF247CBC69ED6F2F9EACB3BF845150", _
        "0x8CABC5A4BDA856E0D0E884D0F4A335CB2457941D", _
        "0xCEBB04B9099141009329E13EDBD8B5CFB14A49A5", _
        "0xD7AA968FCF6AC9691F6ED801BA9291EBBBAFED71", _
        "0xBBBA76A66C54D53BADE77245D9F205F1EB9CC685", _
        "0x39DD14E5DB99F39F68182494C0B48CEFB5DDFDDF", _
        "0x32C2A01B523D973D933FC004237CAB4B792231BF", _
        "0x6AE1A10B7505DDABEECEAFD13B2EC2A8D7286587"]

;other sort
Local $aHashes2[] = ["0x45B265C13EC41DD3272E547A837EF0604E06EF6C", _
        "0x73418EE0D435F0995DE000A0CB9A895B8031D62B", _
        "0xE8BC5E1676E64E9EE77A7EBD56D910D60D453A2A", _
        "0x8CABC5A4BDA856E0D0E884D0F4A335CB2457941D", _
        "0xFF311E2FEC610B2E0A3169435CBC48D5B1B53A57", _
        "0x728EDF8577DF247CBC69ED6F2F9EACB3BF845150", _
        "0x6FB325DDFA9AFCB148B815F41C94F5BBC3735E0B", _
        "0xCEBB04B9099141009329E13EDBD8B5CFB14A49A5", _
        "0x32C2A01B523D973D933FC004237CAB4B792231BF", _
        "0xD7AA968FCF6AC9691F6ED801BA9291EBBBAFED71", _
        "0xBBBA76A66C54D53BADE77245D9F205F1EB9CC685", _
        "0x39DD14E5DB99F39F68182494C0B48CEFB5DDFDDF", _
        "0x6AE1A10B7505DDABEECEAFD13B2EC2A8D7286587"]

_ArrayDisplay($aHashes1)
_ArrayDisplay($aHashes2)

Local $sHash1 = _SumOfHashes($aHashes1)
Local $sHash2 = _SumOfHashes($aHashes2)
ConsoleWrite("Total Hash1: " & $sHash1 & @CRLF)
ConsoleWrite("Total Hash2: " & $sHash2 & @CRLF)


Func _SumOfHashes($aHashes)
    Local $iNumber = 0
    For $i = 0 To UBound($aHashes) - 1
        $iNumber += _CRC32($aHashes[$i])
    Next
    Return _Crypt_HashData($iNumber, $CALG_SHA1)
EndFunc   ;==>_SumOfHashes

Func _CRC32($Data, $CRC32 = -1)
    Local $Opcode = '0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'

    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)

    Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
    DllStructSetData($Input, 1, $Data)

    Local $Ret = DllCall("user32.dll", "uint", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
            "ptr", DllStructGetPtr($Input), _
            "int", BinaryLen($Data), _
            "uint", $CRC32, _
            "int", 0)
    $Input = 0
    $CodeBuffer = 0

    Return $Ret[0]
EndFunc   ;==>_CRC32

Saludos

Link to comment
Share on other sites

10 hours ago, argumentum said:

in Func _Crypt_HashData($vData, $iALG_ID, $fFinal = True, $hCryptHash = 0) it shows that you can continue adding strings, continuing on a prior string, that in itself should have a hash. It should be possible. I just don't know how.

I didn't see this question. Should be something like this:

 

#include <Crypt.au3>
#include <Array.au3>

Local $aHashes1[] = ["0x45B265C13EC41DD3272E547A837EF0604E06EF6C", _
        "0x73418EE0D435F0995DE000A0CB9A895B8031D62B", _
        "0x6FB325DDFA9AFCB148B815F41C94F5BBC3735E0B", _
        "0xE8BC5E1676E64E9EE77A7EBD56D910D60D453A2A", _
        "0xFF311E2FEC610B2E0A3169435CBC48D5B1B53A57", _
        "0x728EDF8577DF247CBC69ED6F2F9EACB3BF845150", _
        "0x8CABC5A4BDA856E0D0E884D0F4A335CB2457941D", _
        "0xCEBB04B9099141009329E13EDBD8B5CFB14A49A5", _
        "0xD7AA968FCF6AC9691F6ED801BA9291EBBBAFED71", _
        "0xBBBA76A66C54D53BADE77245D9F205F1EB9CC685", _
        "0x39DD14E5DB99F39F68182494C0B48CEFB5DDFDDF", _
        "0x32C2A01B523D973D933FC004237CAB4B792231BF", _
        "0x6AE1A10B7505DDABEECEAFD13B2EC2A8D7286587"]

;other sort
Local $aHashes2[] = ["0x45B265C13EC41DD3272E547A837EF0604E06EF6C", _
        "0x73418EE0D435F0995DE000A0CB9A895B8031D62B", _
        "0xE8BC5E1676E64E9EE77A7EBD56D910D60D453A2A", _
        "0x8CABC5A4BDA856E0D0E884D0F4A335CB2457941D", _
        "0xFF311E2FEC610B2E0A3169435CBC48D5B1B53A57", _
        "0x728EDF8577DF247CBC69ED6F2F9EACB3BF845150", _
        "0x6FB325DDFA9AFCB148B815F41C94F5BBC3735E0B", _
        "0xCEBB04B9099141009329E13EDBD8B5CFB14A49A5", _
        "0x32C2A01B523D973D933FC004237CAB4B792231BF", _
        "0xD7AA968FCF6AC9691F6ED801BA9291EBBBAFED71", _
        "0xBBBA76A66C54D53BADE77245D9F205F1EB9CC685", _
        "0x39DD14E5DB99F39F68182494C0B48CEFB5DDFDDF", _
        "0x6AE1A10B7505DDABEECEAFD13B2EC2A8D7286587"]

;~ _ArraySort($aHashes1)
;~ _ArraySort($aHashes2)

_ArrayDisplay($aHashes1)
_ArrayDisplay($aHashes2)


_Crypt_Startup() ; To optimize performance start the crypt library.


Local $sHash1 = _SumOfHashes($aHashes1)
Local $sHash2 = _SumOfHashes($aHashes2)
ConsoleWrite("Total Hash1: " & $sHash1 & @CRLF)
ConsoleWrite("Total Hash2: " & $sHash2 & @CRLF)


 _Crypt_Shutdown() ; Shutdown the crypt library.


Func _SumOfHashes($aHashes)
Local $HashObject=_Crypt_HashData( "", $CALG_SHA1, False)
For $i=0 to UBound($aHashes)-1
    $HashObject=_Crypt_HashData( $aHashes[$i], $CALG_SHA1, False,$HashObject)
Next
Return _Crypt_HashData( "", $CALG_SHA1, True,$HashObject)
EndFunc   ;==>_SumOfHashes

But array must be sorted to match.

 

Saludos

 

Saludos

Link to comment
Share on other sites

Link to comment
Share on other sites

15 hours ago, BrewManNH said:

Where does the hash data come from?

these are hash from files in a folder.

9 hours ago, spudw2k said:

I've also got a HashArray function in my sig.  Just for some more ideas.

Very cool code.

 

11 hours ago, Danyfirex said:

I didn't see this question. Should be something like this:

Well, that is what I did:

#include <Array.au3>
#include <Crypt.au3>

Local $sHashes = "0x45B265C13EC41DD3272E547A837EF0604E06EF6C"&@TAB& _
        "0x73418EE0D435F0995DE000A0CB9A895B8031D62B"&@TAB& _
        "0xE8BC5E1676E64E9EE77A7EBD56D910D60D453A2A"&@TAB& _
        "0x8CABC5A4BDA856E0D0E884D0F4A335CB2457941D"&@TAB& _
        "0xFF311E2FEC610B2E0A3169435CBC48D5B1B53A57"&@TAB& _
        "0x728EDF8577DF247CBC69ED6F2F9EACB3BF845150"&@TAB& _
        "0x6FB325DDFA9AFCB148B815F41C94F5BBC3735E0B"&@TAB& _
        "0xCEBB04B9099141009329E13EDBD8B5CFB14A49A5"&@TAB& _
        "0x32C2A01B523D973D933FC004237CAB4B792231BF"&@TAB& _
        "0xD7AA968FCF6AC9691F6ED801BA9291EBBBAFED71"&@TAB& _
        "0xBBBA76A66C54D53BADE77245D9F205F1EB9CC685"&@TAB& _
        "0x39DD14E5DB99F39F68182494C0B48CEFB5DDFDDF"&@TAB& _
        "0x6AE1A10B7505DDABEECEAFD13B2EC2A8D7286587"
ConsoleWrite('--- "' & HashOfHashes( $sHashes ) & '"' & @CRLF )

Local $aHashes2[] = ["0x45B265C13EC41DD3272E547A837EF0604E06EF6C", _
        "0x73418EE0D435F0995DE000A0CB9A895B8031D62B", _
        "0xE8BC5E1676E64E9EE77A7EBD56D910D60D453A2A", _
        "0x8CABC5A4BDA856E0D0E884D0F4A335CB2457941D", _
        "0xFF311E2FEC610B2E0A3169435CBC48D5B1B53A57", _
        "0x728EDF8577DF247CBC69ED6F2F9EACB3BF845150", _
        "0x6FB325DDFA9AFCB148B815F41C94F5BBC3735E0B", _
        "0xCEBB04B9099141009329E13EDBD8B5CFB14A49A5", _
        "0x32C2A01B523D973D933FC004237CAB4B792231BF", _
        "0xD7AA968FCF6AC9691F6ED801BA9291EBBBAFED71", _
        "0xBBBA76A66C54D53BADE77245D9F205F1EB9CC685", _
        "0x39DD14E5DB99F39F68182494C0B48CEFB5DDFDDF", _
        "0x6AE1A10B7505DDABEECEAFD13B2EC2A8D7286587"]

ConsoleWrite('--- "' & HashOfHashes( $aHashes2 ) & '"' & @CRLF )

Func HashOfHashes( $sTabDelimitedHashes = "" , $sDelemiter = @TAB )
    Local $aHashes, $u1, $n, $bHashes = ""
    If IsArray($sTabDelimitedHashes) Then
        $aHashes = $sTabDelimitedHashes
    Else
        $aHashes = StringSplit( $sTabDelimitedHashes , $sDelemiter , 2)
    EndIf
    _ArraySort($aHashes)
    $u1 = UBound($aHashes) -1
    For $n = 0 To $u1
        $bHashes &= BinaryToString($aHashes[$n])
    Next
    Return _Crypt_HashData($bHashes,$CALG_SHA1)
EndFunc

 

14 hours ago, Danyfirex said:

Hello. This is a simple idea. (it does not mean that it is strictly correct.)

Well, in a way it is, a hash is an identifier and that is what I was looking for. The CRC32 is cool idea, actually, all are good.
I'll use my code*, that is like your last code. The idea is sound. The reason for the tab delimited string example is because, in my project, it actually is a  tab delimited string but I asked of it as if in an array, because, I thought there would be a proper ( and elegant ) way that it is done.
But all in all, all I needed is an unique identifier for the folder ( that in the project is compressed and uploaded ), as to not upload a new ZIP file that even so, the zip may have a different hash, the contents would not have different hashes and to save database space, a hash of the hashes is sufficient. So, if the system finds that a files was modified but the hashes are the same, no actual change in any of the files, instead of asking and keeping so much data, one hash would be enough.

Bottom line, thank you all for your attention to this question of mine. I can now be at ease that my reasoning was ok.

:)

*I'll use my code because it showed to be the faster one.

And an unrelated question: How do I edit the title of this topic ? ( I'd like to add [solved] to it ) 

Edited by argumentum
thanks Synapsee :)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...