other/password.py: alternative_password_generator ignores the requested length when the required characters exceed it
Maintainer antworten meist innerhalb von 2 Tagen
@raaj-2222 arbeitet bereits daran.
Seit 25.10.2026.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 85/100
Rechercherichtung
Öffne other/password.py und lies alternative_password_generator; der Fehler steckt im Block i -= len(chars_incl) / quotient = i // 3 / remainder = i % 3, der sich falsch verhält, wenn i negativ wird. Reproduziere das mit den Snippets aus dem Issue, entscheide dann, ob bei len(chars_incl) > i ein ValueError ausgelöst oder geklemmt werden soll, und prüfe, ob main() diesen Fehler ausgeben muss. Erledigt bedeutet, dass beide Reproduktionsfälle die angeforderte Länge zurückgeben und das bestehende Verhalten für gültige Eingaben unverändert bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Repository commit
6e03a48579ca212a08b36be00378f887dc41a003
Python version (python --version)
Python 3.13.5
Dependencies version (pip freeze)
None needed — other/password.py only uses the standard library (secrets, random, string).
Expected behavior
alternative_password_generator(chars_incl, i) should return a password whose length matches the requested length i (the main() prompt calls it "the max length of your password", and the comment above the function says i = how many letters or characters the password length will be).
Actual behavior
When chars_incl is longer than the requested length i, the subtraction i -= len(chars_incl) makes i negative, and the generator silently returns a password longer than what was asked for:
>>> from other.password import alternative_password_generator
>>> len(alternative_password_generator("abcdefgh", 5)) # asked for 5
8
>>> len(alternative_password_generator("abcd", 3)) # asked for 3
5
In the second case i becomes -1, so quotient = i // 3 is -1 and remainder = i % 3 is 2 (Python's modulo of a negative number is positive), which adds one extra random letter on top of all the required characters.
A user who types a max length smaller than their required-characters string in main() gets a password that silently exceeds the max length they asked for. If the requested length is at least len(chars_incl) everything works as expected.
Steps to reproduce
python - <<'EOF'
from other.password import alternative_password_generator
print(len(alternative_password_generator("abcdefgh", 5))) # expected 5, prints 8
print(len(alternative_password_generator("abcd", 3))) # expected 3, prints 5
EOF
Suspected cause
The negative remainder path in alternative_password_generator:
i -= len(chars_incl)
quotient = i // 3
remainder = i % 3
When len(chars_incl) > i, quotient goes negative (the random() calls then contribute nothing because range() of a negative is empty) while remainder stays positive, so quotient + remainder adds extra characters. Guarding the input (if i < len(chars_incl): raise ValueError(...) or clamping) would keep the generator honest about the requested length.
- Vorherrschende Sprache
- Python
- Sterne
- 225k
- Forks
- 51.2k
- Ø Merge
- 1 T. 13 Std.
- Gemergte PRs (30 T.)
- 32
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TheAlgorithms/Python
-
binomial_distribution overflows at 171 trials even when the result is representableEvtl. vergeben @landfvit hat das vor 1 Tag übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
TheAlgorithms/Python#15656 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
continued_fraction uses float division, producing invalid terms for large integers and raising OverflowErrorEvtl. vergeben @trleo hat das vor 1 Tag übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
TheAlgorithms/Python#15655 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
ciphers/base32.py and ciphers/base85.py encode Unicode code points instead of bytes: output diverges from the spec for non-ASCII, round-trips corrupt chars >= U+0400, arbitrary bytes crashEvtl. vergeben @Nate-br hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
TheAlgorithms/Python#15636 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)Evtl. vergeben @mohammedanasnakhuda hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
TheAlgorithms/Python#15634 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the fileEvtl. vergeben @SakshiYeole hat das vor 4 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 45/100
TheAlgorithms/Python#15637 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in TheAlgorithms/Python
Ähnliche Issues
-
changelog investigate
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
ramnes/notion-sdk-py#433 ·
-
docs pkg:core
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
pydantic/pydantic-ai#11929 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
intake/intake-esm#789 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
MemMachine/MemMachine#1877 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
openedx/openedx-authz#579 ·
Maintainer antworten meist innerhalb von 1 Tag