Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉 適合新手
#15,634 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@mohammedanasnakhuda 已經在處理了。

開始於 2026年10月25日。

  • #15640 來自 @mohammedanasnakhuda —— 已關閉,未合併
  • #15641 來自 @mohammedanasnakhuda —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
88/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
cryptography

研究方向

從 ciphers/des_ecb.py 的 Operations.string_to_bitset(約第 151 行)開始,這裡 format(ord(char), "08b") 對高於 U+00FF 的碼位會輸出超過 8 個位元,使整個位元流偏離位元組邊界。回報者建議,要麼對非 Latin-1 輸入擲出 ValueError,要麼先編碼為 UTF-8 位元組;請決定哪種做法能保持 encrypt/decrypt 的有效往返。用 issue 中的 python 單行指令重現問題,修正編碼路徑,並對 ASCII、Latin-1 以及 "€100" 和 "日本語" 這類多位元組字串驗證往返;一個斷言往返相等的小 test 即可視為完成。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
Python
星號
225k
分支
51.2k
平均合併
1 天 8 小時
30 天內合併 PR
40

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TheAlgorithms/Python 的其他 Issue

查看 TheAlgorithms/Python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。