ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)
維護者通常 1 天內回覆
@mohammedanasnakhuda 已經在處理了。
開始於 2026年10月25日。
評估
- 難度
- 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
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TheAlgorithms/Python 的其他 Issue
-
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 crash可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 88/100
TheAlgorithms/Python#15636 · 1 則留言 ·
維護者通常 1 天內回覆
-
other/password.py: alternative_password_generator ignores the requested length when the required characters exceed it可能已有人在做 @raaj-2222 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 85/100
TheAlgorithms/Python#15633 · 1 則留言 ·
維護者通常 1 天內回覆
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the file可能已有人在做 @SakshiYeole 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 45/100
TheAlgorithms/Python#15637 ·
維護者通常 1 天內回覆
-
hashes/adler32.py: checksum diverges from the Adler-32 spec for any non-ASCII input (sums Unicode code points instead of bytes)可能已有人在做 @SwetaKumari7 於 2 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 35/100
TheAlgorithms/Python#15635 ·
維護者通常 1 天內回覆
-
Optimize Node.has_loop to use constant auxiliary space instead of O(N) space可能已有人在做 @mohitjoshi-hey 於 12 天前認領。 未關閉enhancement
難度 2/5 1-3 小時 新手友好度 15/100
TheAlgorithms/Python#15576 · 1 則留言 ·
維護者通常 1 天內回覆
查看 TheAlgorithms/Python 的全部 Issue
相似的 Issue
-
automated issue linkchecker report
難度 2/5 1-3 小時 新手友好度 66/100
QuantEcon/lecture-python.myst#1098 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
podly-pure-podcasts/podly_pure_podcasts#279 ·
維護者通常 1 天內回覆
-
template-proposal
難度 1/5 1 小時以內 新手友好度 78/100
-
難度 1/5 1 小時以內 新手友好度 82/100
OpenShot/openshot-qt#6230 ·
維護者通常 1 天內回覆