Skip to content

Commit 504b1de

Browse files
author
Jakub Kramarz
committed
implemented _unhash using Horner's method
1 parent 07caba3 commit 504b1de

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

hashids.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ def _unhash(hashed, alphabet):
5656
"""Restores a number tuple from hashed using the given `alphabet` index."""
5757
number = 0
5858
len_alphabet = len(alphabet)
59-
base = 1
60-
for character in hashed[::-1]:
59+
for character in hashed:
6160
position = alphabet.index(character)
62-
number += position * base
63-
base *= len_alphabet
61+
number *= len_alphabet
62+
number += position
6463
return number
6564

6665

0 commit comments

Comments
 (0)