Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)

Aperta Adatta ai principianti
#15,634 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mohammedanasnakhuda ci sta già lavorando.

Dal 25/10/2026.

  • #15640 di @mohammedanasnakhuda — chiusa senza merge
  • #15641 di @mohammedanasnakhuda — aperta

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

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TheAlgorithms/Python

Tutte le issue di TheAlgorithms/Python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.