簡體   English   中英

為什么它會跳過字符串的最后一個字符

[英]Why it skips the last character of string

我在這段代碼中有問題。

為什么它會跳過我的字符串的最后一個字符。 假設我想為“timeGetTime”計算 hash,循環在“e”字符處停止。

我嘗試打印 API 名稱,它正確打印了所有字符。

編輯:

正確的 hash 是0xFF407C2F但 output 是0xE07FFA03

def ROR(data, shift, size=32):
    shift %= size
    body = data >> shift
    remains = (data << (size - shift)) - (body << size)
    return (body + remains)


def calculateHash(apiName):
    result = 0
    for ch in apiName:
        result = ROR(result, 0x13)
        result +=  ord(ch)

    return result

您需要更改行的順序,以便最后一個字母也得到其他 function 的結果 -

for ch in apiName:
    result +=  ord(ch)
    result = ROR(result, 0x13) # What you did was change the result later

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM