简体   繁体   English

IndexError:字符串索引超出范围 - Python

[英]IndexError: string index out of range - Python

Im getting this error.我收到这个错误。

mac_decrypt+=decrypt_datei[i]
IndexError: string index out of range

I tried everything but no success.我尝试了一切,但没有成功。 Can someone help me pls, where I do mistake!有人可以帮助我吗,我在哪里做错了!

Here is Code:这是代码:

lauf = len(decrypt_datei) - 1
nachricht_decrypt = ''
nachricht_length = ord(decrypt_datei[lauf])
nachricht_length = len(decrypt_datei) - (nachricht_length + 1)
lauf -= 1
while nachricht_length <= lauf:
    nachricht_decrypt += decrypt_datei[nachricht_length]
    nachricht_length += 1
print('entschluesselung fertig!')
print('mac Ueberpruefung:')

while s == False:
    # Mac UeberprUefen/ Nachricht zeigen
    macpassword_try = raw_input('Geben Sie den Macpassword:')
    hash_macpassword_try = hashlib.sha512(macpassword_try).hexdigest()

    lauf = ord(decrypt_datei[0])
    mac_decrypt = ''
    i = 1
    while i <= lauf:
        mac_decrypt += decrypt_datei[i]
        i += 1

The problem probably lies in:问题大概出在:

lauf = ord(decrypt_datei[0])

ord returns an integer representing the Unicode code point of the character. ord返回一个整数,表示字符的 Unicode 代码点。

If you would have ord('a') that would return 97 thus if your string decrypt_datei contains 'a' and len(decrypt_datei) is smaller than 97 it will result in string index out of range如果您有ord('a')将返回97因此如果您的字符串decrypt_datei包含'a'并且len(decrypt_datei)小于97它将导致string index out of range

I suspect logical error here.我怀疑这里有逻辑错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM