ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)
Les mainteneurs répondent en général sous 2 jours
@mohammedanasnakhuda y travaille déjà.
Depuis le 25/10/2026.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 88/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- python
- Domaine
- cryptography
Piste de recherche
Commence dans ciphers/des_ecb.py à Operations.string_to_bitset (autour de la ligne 151), où format(ord(char), "08b") émet plus de 8 bits pour les points de code supérieurs à U+00FF et décale tout le flux de bits hors de la frontière d'octet. Le rapporteur suggère soit de lever une ValueError pour une entrée non Latin-1, soit d'encoder d'abord en octets UTF-8 ; décide laquelle garde encrypt/decrypt comme un aller-retour valide. Reproduis le problème avec le one-liner python de l'issue, corrige le chemin d'encodage et vérifie les allers-retours pour les chaînes ASCII, Latin-1 et multioctets comme "€100" et "日本語" ; un petit test affirmant l'égalité aller-retour marquerait cela comme terminé.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Repository commit
6e03a48579ca212a08b36be00378f887dc41a003
Python version (python --version)
Python 3.13.5
Dependencies version (pip freeze)
None needed — ciphers/des_ecb.py only uses the standard library.
Expected behavior
Encrypting a text and decrypting the result with the same key should round-trip to the original text. Nothing in the module docstring restricts the input to ASCII.
Actual behavior
Any character with a code point above 0xFF silently corrupts the data: the decrypted text is not the original, and no error is raised.
>>> from ciphers.des_ecb import Des
>>> key = "0123456789abcdef"
>>> ct = Des.encrypt(key, "€100")
>>> Des.decrypt(key, ct)
'\x82°ÄÀÀ'
Same for CJK input:
>>> ct = Des.encrypt(key, "日本語")
>>> Des.decrypt(key, ct)
'ËË\x9c²*x'
ASCII and Latin-1 text round-trips fine, so the bug is easy to miss with English-only examples.
Steps to reproduce
python - <<'EOF'
from ciphers.des_ecb import Des
key = "0123456789abcdef"
print(Des.decrypt(key, Des.encrypt(key, "€100")) == "€100") # prints False
print(Des.decrypt(key, Des.encrypt(key, "hello")) == "hello") # prints True
EOF
Suspected cause
Operations.string_to_bitset builds the bitset with format(ord(char), "08b") (ciphers/des_ecb.py:151). The 08b format is a minimum width, so for ord(char) > 255 it emits more than 8 bits — e.g. "€" (U+20AC) becomes 14 bits. That shifts every subsequent bit off the 8-bit boundary that the block partitioning, padding, and bitset_to_string/bitset_to_hex conversions rely on, so the ciphertext for such text can no longer be decoded into the original string. Clamping to one byte (e.g. raising a ValueError for non-Latin-1 input, or encoding to UTF-8 bytes first) would keep the round-trip honest.
- Langage dominant
- Python
- Étoiles
- 225k
- Forks
- 51.2k
- Merge moyen
- 1 j 13 h
- PR mergées (30 j)
- 32
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de TheAlgorithms/Python
-
binomial_distribution overflows at 171 trials even when the result is representablePeut-être pris @landfvit l’a pris il y a 1 jour. Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
TheAlgorithms/Python#15656 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
continued_fraction uses float division, producing invalid terms for large integers and raising OverflowErrorPeut-être pris @trleo l’a pris il y a 1 jour. Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
TheAlgorithms/Python#15655 · 2 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
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 crashPeut-être pris @Nate-br l’a pris il y a 3 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
TheAlgorithms/Python#15636 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
other/password.py: alternative_password_generator ignores the requested length when the required characters exceed itPeut-être pris @raaj-2222 l’a pris il y a 4 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
TheAlgorithms/Python#15633 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the filePeut-être pris @SakshiYeole l’a pris il y a 4 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 45/100
TheAlgorithms/Python#15637 ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de TheAlgorithms/Python
Issues similaires
-
enhancement help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
Git-Hospital/githealthcheck#61 ·
Les mainteneurs répondent en général sous 1 jour
-
changelog investigate
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
ramnes/notion-sdk-py#433 ·
-
Partial method descriptors raise on class accessPeut-être pris @Gambit-Checkmate l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
Les mainteneurs répondent en général sous 19 jours
-
docs pkg:core
Difficulté 1/5 Moins d'une heure Accessibilité débutants 84/100
pydantic/pydantic-ai#11929 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
intake/intake-esm#789 ·