Sign in to follow this  
Followers 0
ngskicker

help to hash

4 posts in this topic

#1 ·  Posted (edited)

i have sorce code vb, but i dont know vb, so i request you to help me if you wish

this code generate a hash code, i need to generate hash code, so long i have to generate it manually, i hope you can help me to generate it direct in autoit... please help me, i have spent my time to build this application

this is the code in vb

CODE
Public Function hashCode(Value)

's(0) * 31 to the power n-1 + s(1) * 31 to the power n-2 and so on...till s(n-1)

Const maxInt = 4294967295#

Const maxPostInt = 2147483647

Dim h As Currency

Dim div As Long

Dim i As Long

h = 0

For i = 1 To Len(Value)

h = h * 31 + Asc(Mid(Value, i, 1))

If (h > maxInt) Then

div = Int(h / (maxInt + 1))

h = h - (div * (maxInt + 1))

End If

Next i

If h > maxPostInt Then

h = h - maxInt - 1

End If

hashCode = h

End Function

and this in asm

CODE
;=====================

.386

.model flat,stdcall

option casemap:none

include \masm32\include\windows.inc

include \masm32\include\user32.inc

include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib

includelib \masm32\lib\kernel32.lib

GetHashCode PROTO:DWORD

.data

hCode db "4JGEahik3mypass",0

.data?

printBuffer db 100 dup(?)

storeBuffer db 100 dup(?)

.code

start:

invoke GetHashCode, addr hCode

invoke ExitProcess,0

GetHashCode proc hCodeFrmS:DWORD

LOCAL temp:DWORD

jmp @F

printtemplate db "hashcode for the above string is %xh ",0

@@:

invoke RtlZeroMemory, addr printBuffer, 100

mov temp,0

mov esi, hCodeFrmS

mov edi, offset storeBuffer

continue:

mov ecx, 1

rep movsb

mov al,[esi-1]

mov eax,temp

mov edx,31

mul edx

mov temp,eax

xor eax,eax

mov al,[esi-1]

add eax,temp

mov temp,eax

push temp

push offset printtemplate

push offset printBuffer

call wsprintfA

add esp,12

mov al,[esi]

cmp al,0

jne continue

invoke MessageBox,0, addr printBuffer,addr storeBuffer,0

ret

GetHashCode endp

end start

;=====================

Edited by ngskicker

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is this right? VB is really simple to convert to AutoIt

Func hashCode($Value)
;'s(0) * 31 to the power n-1 + s(1) * 31 to the power n-2 and so on...till s(n-1)
    Local Const $maxInt = 4294967295
    Local Const $maxPostInt = 2147483647
    Local $h=0, $div, $i
    $Value = StringToASCIIArray($Value)
    ; Possibly, you will need the Codes as ASCII, not as UTF16. Then use the line below:
;~  $Value = StringToASCIIArray($Value,0,Default,1)
    For $i = 0 To UBound($Value)-1
        $h = $h * 31 + $Value[$i]
        If ($h > $maxInt) Then
            $div = Int($h / ($maxInt + 1))
            $h = $h - ($div * ($maxInt + 1))
        EndIf
    Next
    If $h > $maxPostInt Then $h = $h - $maxInt - 1
    Return $h
EndFunc

MsgBox(0, '', hashCode("abc"))
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

yourcode work, thnks :D

Edited by ngskicker

Share this post


Link to post
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
Sign in to follow this  
Followers 0