Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#15,634 コメント 0 件 リアクション 0 件 担当者 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" や "日本語" のようなマルチバイト文字列のラウンドトリップを検証してください。ラウンドトリップの一致を assert する小さなテストがあれば完了とみなせます。

索引モデルが 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時間
マージ済み PR(30日)
40

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TheAlgorithms/Python のほかの issue

TheAlgorithms/Python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。