ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)
I maintainer di solito rispondono entro 1 giorno
@mohammedanasnakhuda ci sta già lavorando.
Dal 25/10/2026.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 88/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- cryptography
Direzione di ricerca
Inizia in ciphers/des_ecb.py presso Operations.string_to_bitset (intorno alla riga 151), dove format(ord(char), "08b") emette più di 8 bit per i code point superiori a U+00FF e sposta l'intero flusso di bit fuori dal confine del byte. Chi ha segnalato suggerisce oppure di sollevare un ValueError per input non Latin-1, oppure di codificare prima in byte UTF-8; decidi quale opzione mantiene encrypt/decrypt come un round trip valido. Riproduci il problema con il one-liner python nell'issue, correggi il percorso di codifica e verifica i round trip per stringhe ASCII, Latin-1 e multibyte come "€100" e "日本語"; un piccolo test che asserisca l'uguaglianza del round trip concluderebbe questo lavoro.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 225k
- Fork
- 51.2k
- Merge medio
- 1g 8h
- PR unite (30g)
- 40
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TheAlgorithms/Python
-
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 crashForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
TheAlgorithms/Python#15636 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
other/password.py: alternative_password_generator ignores the requested length when the required characters exceed itForse già presa @raaj-2222 l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
TheAlgorithms/Python#15633 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the fileForse già presa @SakshiYeole l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
TheAlgorithms/Python#15637 ·
I maintainer di solito rispondono entro 1 giorno
-
hashes/adler32.py: checksum diverges from the Adler-32 spec for any non-ASCII input (sums Unicode code points instead of bytes)Forse già presa @SwetaKumari7 l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
TheAlgorithms/Python#15635 ·
I maintainer di solito rispondono entro 1 giorno
-
Optimize Node.has_loop to use constant auxiliary space instead of O(N) spaceForse già presa @mohitjoshi-hey l’ha presa 12 giorni fa. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 15/100
TheAlgorithms/Python#15576 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TheAlgorithms/Python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
UKGovernmentBEIS/optstop#10 ·
-
maintenance
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
pollen-robotics/reachy_mini#1508 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] `cloud-keys.env` values retain enclosing quotes causing 401 Unauthorized, and missing utf-8 encoding crashes on WindowsForse già presa @divyanshu07-code l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
open-jarvis/OpenJarvis#1192 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
sylvainmetayer/homelab#851 ·
I maintainer di solito rispondono entro 1 giorno