Encryption

具有固定密鑰和已知明文關係的 XOR 密碼

  • July 1, 2020

我有 3 條消息,每條消息都經過 XOR 編碼,並且該 XOR 密碼的每條消息都使用相同的密鑰。

  • 編碼消息 1: $ e_1,=,00100111010 $
  • 編碼消息 2: $ e_2,=,01001110110 $
  • 編碼消息 3: $ e_3,=,11010110101 $

我還有一個額外的資訊:我知道解碼的內容 $ e_1\oplus e_2 $ 等於解碼後的內容 $ e_3 $ .

為了獲得密鑰並解碼消息的內容,人們將如何解決這個問題?

我對此有點陌生,所以可能有更好的方法來解決這個問題,但這就是我解決它的方法。如果我理解正確,給出的額外參數寫為: $$ \mathtt{}({e}{1} \oplus k) \oplus ({e}{2} \oplus k) = e_{3} \oplus k $$ (即e1的解碼內容與e2的解碼內容異或等於e3的解碼內容)

括號僅提供可讀性,因此沒有它們,等式是相同的。這意味著我們有$$ \mathtt{}{e}{1} \oplus k \oplus {e}{2} \oplus k = e_{3} \oplus k $$

有2個 ” $ \mathtt{}\oplus k $ “在此處的左側,因此可以將其刪除以獲取以下內容:

$$ \mathtt{}{e}{1}\oplus {e}{2} = e_{3} \oplus k $$

右手邊也可以換成 $ \mathtt{}m_{3} $ 表示已解密 $ \mathtt{}e_{3} $ :

$$ \mathtt{}{e}{1}\oplus {e}{2} = m_{3} $$

$ \mathtt{}e_{1} $ 和 $ \mathtt{}e_{2} $ 給定,通過異或運算我們可以得到:

$$ \mathtt{}{m}{3} = 1101001100 $$ 我們也知道: $$ \mathtt{}{m}{3} = {e}_{3} \oplus {k} $$

現在我們兩者都有 $ \mathtt{}m_{3} $ 和 $ \mathtt{}e_{3} $ ,我們現在可以求解 $ \mathtt{}k $ :

  1. 兩邊異或 $ \mathtt{}e_{3} $ $$ \mathtt{}{m}{3} \oplus {e}{3} = {e}{3} \oplus {e}{3} \oplus {k} $$
  2. 消除 $ \mathtt{}e_{3} \oplus e_{3} $ 從右手邊: $$ \mathtt{}{m}{3} \oplus {e}{3} = {k} $$
  3. 代入 $ \mathtt{}m_{3} $ 和 $ \mathtt{}e_{3} $ 的價值觀: $$ \mathtt{}1101001100 \oplus 11010110101 = {k} $$
  4. 給…: $$ \mathtt{}k = 10111111001 $$

您現在可以解碼所有 3 條加密消息: $$ \mathtt{}m_{1} = 10011000011 $$ $$ \mathtt{}m_{2} = 11110001111 $$ $$ \mathtt{}m_{3} = 01101001100 $$ 希望有幫助。

這個問題是關於按位異或運算符(也稱為 XOR 或 $ \oplus $ ),這在密碼學中很常見。它是具有類似名稱和註釋的位運算符XOR位運算符,真值表是

$$ \begin{array}{c|c|c|c|c|c} \text{first/left input}&a&0&0&1&1\ \text{second/right input}&b&0&1&0&1\ \hline \text{output}&a\oplus b&0&1&1&0 \end{array} $$

位運算符對相等長度的位串進行操作,並將布爾運算符應用於其輸入中相等等級的位,以在輸出中形成該等級的位。因此,按位異或運算符只是將上表應用於輸入的每個位。一個例子 $ 8 $ -位位串:

$$ \begin{array}{c|c|c|c} &\text{bitstrings}&\text{binary}&\text{hexadecimal}\ \hline \text{first/left input}&A&00110001&\tt{31_h}\ \text{second/right input}&B&01011100&\tt{5c_h}\ \hline \text{output}&A\oplus B&01101101&\tt{6d_h}\ \end{array} $$

按位異或運算符 $ \oplus $ 繼承位運算符的屬性 $ \oplus $ :

  • 關聯性: $ \forall X $ , $ \forall Y $ , $ \forall Z $ , $ \ (X\oplus Y)\oplus Z,=,X\oplus(Y\oplus Z) $
  • 交換性: $ \forall X $ , $ \forall Y $ , $ \ X\oplus Y,=,Y\oplus X $
  • 有一個標識元素,即全零位串: $$ \forall X,\ X\oplus{\underbrace{0\ldots0}{|X|\text{ bits}}},=,X,=,{\underbrace{0\ldots0}{|X|\text{ bits}}}\oplus X $$ 在哪裡 $ |X| $ 是位寬 $ X $ .

等效地: $ \forall X $ , $ \ X\oplus0^{|X|},=,X,=,0^{|X|}\oplus X $ .

為了 $ 8 $ - 位操作數,如上例所示, $ 0^{|X|} $ 是 $ 00000000 $ 或者 $ \tt{00_h} $ .

  • 每個元素都是它自己的(或相反): $ \forall X $ , $ \ X\oplus X,=,0^{|X|},=,{\underbrace{0\ldots0}_{|X|\text{ bits}}} $

前三個性質是交換群(等價於:阿貝爾群)的內部定律(等價於:運算)的性質。

最後一個屬性使組成為布爾組。具體來說,布爾組的位串 $ n $ 位,注意到 $ \left({0,1}^n,\oplus\right) $

該問題適用於該組 $ n $ 十一。它歸結為將陳述寫成方程,並通過應用所述屬性來解決這些問題。如果一個被卡住了,評論中有提示,另一個答案中有一個可行的解決方案。

引用自:https://crypto.stackexchange.com/questions/80774