Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta Para iniciantes
#15,634 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@mohammedanasnakhuda já está trabalhando nisso.

Desde 25/10/2026.

  • #15640 de @mohammedanasnakhuda — fechado sem integrar
  • #15641 de @mohammedanasnakhuda — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
88/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
cryptography

Direção de pesquisa

Comece em ciphers/des_ecb.py em Operations.string_to_bitset (por volta da linha 151), onde format(ord(char), "08b") emite mais de 8 bits para code points acima de U+00FF e desloca todo o fluxo de bits para fora do limite de byte. Quem reportou sugere ou lançar um ValueError para entradas não Latin-1 ou codificar primeiro para bytes UTF-8; decida qual opção mantém encrypt/decrypt como um round trip válido. Reproduza com o one-liner python do issue, corrija o caminho de codificação e verifique os round trips para strings ASCII, Latin-1 e multibyte como "€100" e "日本語"; um pequeno test que verifique a igualdade do round trip marcaria isso como concluído.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
225k
Forks
51.2k
Merge médio
1d 8h
PRs com merge (30d)
40

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de TheAlgorithms/Python

Todas as issues de TheAlgorithms/Python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.