0

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
1
  • can you print the variables lauf and decrypt_datei ? print it before the line while i <= lauf Commented Dec 28, 2019 at 12:21

1 Answer 1

1

The problem probably lies in:

lauf = ord(decrypt_datei[0])

ord returns an integer representing the Unicode code point of the character.

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

I suspect logical error here.

Sign up to request clarification or add additional context in comments.

1 Comment

It is also good to point that the line in question is lauf = ord(decrypt_datei[0]).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.