#include-once ; #INDEX# ======================================================================================================================= ; Title .........: Corned Beef Hash ; AutoIt Version : 3.3.12.0 ; Description ...: A reasonably speedy and overly simplistic hash generator (definately not a cryptographic hash) ; I had a minor project that I didn't feel like putting in the effort to use any recognized hashing algorithm, ; so I make this one as a quick and dirty, just for sh*ts and giggles algorithm. Useable, but don't take it ; seriously. Maybe just an example of how you can compartmentalize your UDF and avoid using global variables. ; Author(s) .....: David Williams (willichan) ; Dll ...........: ; Links .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_CornedBeef_Add ;_CornedBeef_Destroy ;_CornedBeef_Hash ;_CornedBeef_Initialize ;_CornedBeef_Read ;_CornedBeef_Reset ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ; =============================================================================================================================== ; #VARIABLES# =================================================================================================================== ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== ; =============================================================================================================================== ; #No_Doc_Function# ============================================================================================================= ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CornedBeef_Add ; Description ...: Adds a single character to the hash. ; Syntax ........: _CornedBeef_Add(Byref $aCbObject, $sData) ; Parameters ....: $aCbObject - The hash object returned by _CornedBeef_Initialize ; $sData - The character to add to the hash (anything after the first character is ignored) ; Return values .: The current hash as a 32 bit integer ; Author ........: David Williams (willichan) ; Modified ......: ; Remarks .......: This is intended for use when you are doing something else with the data at the same time as you are hashing. ; Related .......: _CornedBeef_Initialize,_CornedBeef_Read ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _CornedBeef_Add(ByRef $aCbObject, $sData) Local $iMyData = Asc(StringLeft($sData, 1)) Local $iPotato = BitAND($iMyData, 3) * 8 ;If you don't add potato, its just corned beef. If $iPotato <> 0 Then $iMyData = BitShift($iMyData, -$iPotato) $aCbObject[1] = BitXOR($aCbObject[1], $iMyData) Return _CornedBeef_Read($aCbObject) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CornedBeef_Destroy ; Description ...: Clears the hash object to release memory ; Syntax ........: _CornedBeef_Destroy(Byref $aCbObject) ; Parameters ....: $aCbObject - The hash object returned by _CornedBeef_Initialize ; Return values .: None ; Author ........: David Williams (willichan) ; Modified ......: ; Remarks .......: ; Related .......: _CornedBeef_Initialize ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _CornedBeef_Destroy(ByRef $aCbObject) $aCbObject = 0; EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CornedBeef_Hash ; Description ...: Hashes the data supplied ; Syntax ........: _CornedBeef_Hash(Byref $aCbObject, Byref $sData[, $bReset = True]) ; Parameters ....: $aCbObject - The hash object returned by _CornedBeef_Initialize. ; $sData - The data to be hashed ; $bReset - [optional] Should the hash be reset to starting condition? Default is True. ; Return values .: The current or generated hash as a 32 bit integer ; Author ........: David Williams (willichan) ; Modified ......: ; Remarks .......: ; Related .......: _CornedBeef_Initialize,_CornedBeef_Reset,_CornedBeef_Add,_CornedBeef_Read ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _CornedBeef_Hash(ByRef $aCbObject, $sData, $bReset = True) Local $i Local $iDataLen = StringLen($sData) If $bReset Then _CornedBeef_Reset($aCbObject) If $iDataLen > 0 Then For $i = 1 to $iDataLen _CornedBeef_Add($aCbObject, StringMid($sData, $i, 1)) Next EndIf Return _CornedBeef_Read($aCbObject) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CornedBeef_Initialize ; Description ...: Get everything ready to start ; Syntax ........: _CornedBeef_Initialize([$iSeed = 3224374275]) ; Parameters ....: $iSeed - [optional] a 32-bit integer integer value to use as the seed for the hash. ; Default is 3224374275. ; Return values .: Array containing the hash object ; Author ........: David Williams (willichan) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _CornedBeef_Initialize($iSeed = 3224374275) Local $aCbObject = [$iSeed, $iSeed] ;[Seed, Hash] Return $aCbObject EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CornedBeef_Read ; Description ...: Retrieves the current hash from the hash object ; Syntax ........: _CornedBeef_Read(Byref $aCbObject) ; Parameters ....: $aCbObject - The hash object returned by _CornedBeef_Initialize ; Return values .: The current hash as a 32 bit integer ; Author ........: David Williams (willichan) ; Modified ......: ; Remarks .......: ; Related .......: _CornedBeef_Initialize ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _CornedBeef_Read(ByRef $aCbObject) Return $aCbObject[1] EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CornedBeef_Reset ; Description ...: ; Syntax ........: _CornedBeef_Reset(Byref $aCbObject) ; Parameters ....: $aCbObject - The hash object returned by _CornedBeef_Initialize ; Return values .: None ; Author ........: David Williams (willichan) ; Modified ......: ; Remarks .......: ; Related .......: _CornedBeef_Initialize ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _CornedBeef_Reset(ByRef $aCbObject) $aCbObject[1] = $aCbObject[0] EndFunc