diff --git a/content/lessons/cryptography/block-ciphers-and-aes/ar.md b/content/lessons/cryptography/block-ciphers-and-aes/ar.md index 5f271ea..a10ad5b 100644 --- a/content/lessons/cryptography/block-ciphers-and-aes/ar.md +++ b/content/lessons/cryptography/block-ciphers-and-aes/ar.md @@ -16,27 +16,27 @@ variables: ## Try it -1. انظر إلى العمودين من المربعات الصغيرة، A على اليسار وB على اليمين. يبدآن ككتلة واحدة من 16 بتًا، باستثناء بت واحد مقلوب. -2. أبقِ «flip» على 0 وغيّر «rounds» إلى 0 ثم 1 ثم 2 ثم 3 ثم 4. تُظهر قراءة «البتات المختلفة» 1 ثم 3 ثم 9 ثم 5 ثم 5 من 16: بت واحد مقلوب ينتشر في الكتلة كلها. -3. و«rounds» على 4، اضبط «flip» على 8 ثم على 15. يختلف الآن بت آخر من المدخل، وتُظهر القراءة 7 / 16 ثم 6 / 16. ينتشر التغيير مهما كان البت الذي اخترته. +1. انظر إلى المرحلة الأولى في الأعلى: الرسالة A هي الكلمة «hi» والرسالة B هي «Hi». كتابة أول حرف كبيرًا تغيّر بتًا واحدًا فقط من الـ16، ويحدده عمود أحمر. +2. أبقِ «البت المدخل المختلف» على 2 وغيّر «عدد جولات الخلط» إلى 0 ثم 1 ثم 2 ثم 3 ثم 4. تُظهر قراءة «البتات المختلفة» 1 ثم 2 ثم 6 ثم 8 ثم 8 من 16: بت واحد مقلوب ينتشر حتى يختلف نصف الكتلة. +3. و«عدد جولات الخلط» على 4، اضبط «البت المدخل المختلف» على 10 ثم على 15. تصير B «hI» ثم «hh»، وتُظهر القراءة 11 / 16 ثم 8 / 16. ينتشر التغيير مهما كان البت الذي اخترته. ## Real-life examples -1. **إرسال كتلة بلا أي جولة.** «rounds» = 0 يتخطى كل خلط. A وB متطابقتان إلا في بت مدخل واحد، فيبقى الفرق بينهما مربعًا واحدًا بالضبط في الأسفل، تمامًا كبيانات غير مخلوطة إطلاقًا. -2. **رسالة ممزوجة جزئيًا.** «rounds» = 2 ينشر ذلك الفرق من بت واحد إلى 9 مربعات من 16، لكن النمط بعد جولتين فقط ما زال سهل التوقع، كما في شيفرة ضعيفة. -3. **رسالة ممزوجة بالكامل، من بت مختلف.** «rounds» = 4 مع «flip» = 8 يُظهر أن بتًا مختلفًا في البداية ينتهي أيضًا بخلط نحو نصف الكتلة، تمامًا كما تفعل عشر جولات AES الحقيقية بكتلة كاملة من 128 بتًا. +1. **إرسال كتلة بلا أي جولة.** «عدد جولات الخلط» = 0 يتخطى كل خلط. A وB متطابقتان إلا في بت مدخل واحد، فيبقى الفرق بينهما عمودًا أحمر واحدًا بالضبط، تمامًا كبيانات غير مخلوطة إطلاقًا. +2. **رسالة ممزوجة جزئيًا.** «عدد جولات الخلط» = 2 ينشر ذلك الفرق من بت واحد إلى 6 بتات من 16، لكن النمط بعد جولتين فقط ما زال سهل التوقع، كما في شيفرة ضعيفة. +3. **رسالة ممزوجة بالكامل، من بت مختلف.** «عدد جولات الخلط» = 4 مع «البت المدخل المختلف» = 3 (تصير B «xi») يُظهر أن بتًا مختلفًا في البداية ينتهي أيضًا بخلط نصف الكتلة، 8 من 16، تمامًا كما تفعل عشر جولات AES الحقيقية بكتلة كاملة من 128 بتًا. ## Test yourself -1. ادفع «rounds» إلى 4، أقصى ما تقدّمه هذه الشيفرة المصغّرة. -2. ادفع «flip» إلى 15، آخر بت في المدخل. -3. اضبط «rounds» على 4 وأعد «flip» إلى 0، وعُدّ كم من المربعات الـ16 في الأسفل يختلف بين A وB. +1. ادفع «عدد جولات الخلط» إلى 4، أقصى ما تقدّمه هذه الشيفرة المصغّرة. +2. ادفع «البت المدخل المختلف» إلى 15، آخر بت في المدخل. +3. اضبط «عدد جولات الخلط» على 4 وأعد «البت المدخل المختلف» إلى 2، وعُدّ كم بتًا من الـ16 في المرحلة الأخيرة يختلف بين A وB. ## Intuition -خذ كتلة صغيرة من 16 بتًا فقط، صغيرة بما يكفي لرسمها كاملة على الشاشة، واقلب بتًا واحدًا منها قبل تشفير النسخة الأصلية والنسخة المقلوبة جنبًا إلى جنب. العمود الأيسر من المربعات الصغيرة هو الكتلة A، والعمود الأيمن هو الكتلة B، مطابقة لـA إلا في بت واحد يحدده منزلق «flip». حرّك «rounds» من 0 إلى 4 وراقب صفًا جديدًا يظهر مع كل جولة. عند «rounds» = 0 يبقى الفرق بين العمودين مربعًا واحدًا بالضبط، لكن كل جولة تمزج جزءًا من المفتاح، وتستبدل كل مجموعة من 4 بتّات عبر جدول ثابت، ثم تُعيد ترتيب البتّات الـ16 كلها في مواضع جديدة. +خذ كتلة صغيرة من 16 بتًا فقط، هي الحرفان «hi»، صغيرة بما يكفي لرسمها كاملة على الشاشة، واقلب بتًا واحدًا منها قبل تشفير النسخة الأصلية والنسخة المقلوبة جنبًا إلى جنب. في كل مرحلة من الرسم تقع الكتلة A فوق الكتلة B، وB مطابقة لـA إلا في بت واحد يحدده منزلق «البت المدخل المختلف»، ويحدد عمود أحمر كل بت يختلفان فيه. حرّك «عدد جولات الخلط» من 0 إلى 4 وراقب مرحلة جديدة تمتلئ مع كل جولة. عند 0 جولات يبقى الفرق بين الكتلتين بتًا واحدًا بالضبط، لكن كل جولة تمزج جزءًا من المفتاح، وتستبدل كل مجموعة من 4 بتّات عبر جدول ثابت، ثم تُعيد ترتيب البتّات الـ16 كلها في مواضع جديدة. -عند الصف الأخير، «rounds» = 4، يختلف نحو نصف المربعات الـ16 بين A وB في لونها، رغم أن A وB لم يفترقا في البداية سوى ببت واحد. هذا الانتشار هو بالضبط ما يفعله AES الحقيقي على نطاق أوسع، إذ يشفّر كتلة كاملة بالصيغة $C = E_K(M)$، رسالة $M$ ممزوجة عبر جولات متكررة تحت مفتاح $K$. +عند المرحلة الأخيرة، حين يكون «عدد جولات الخلط» = 4، يختلف نحو نصف البتات الـ16 بين A وB (8 من 16 في الإعدادات الأولى)، رغم أن A وB لم يفترقا في البداية سوى ببت واحد. هذا الانتشار هو بالضبط ما يفعله AES الحقيقي على نطاق أوسع، إذ يشفّر كتلة كاملة بالصيغة $C = E_K(M)$، رسالة $M$ ممزوجة عبر جولات متكررة تحت مفتاح $K$. ## Formal diff --git a/content/lessons/cryptography/block-ciphers-and-aes/en.md b/content/lessons/cryptography/block-ciphers-and-aes/en.md index 90da99f..e8c5bce 100644 --- a/content/lessons/cryptography/block-ciphers-and-aes/en.md +++ b/content/lessons/cryptography/block-ciphers-and-aes/en.md @@ -14,27 +14,27 @@ variables: ## Try it -1. Look at the two towers of small squares, A on the left and B on the right: they start as the same 16-bit block, except for one flipped bit. -2. Keep «flip» at 0 and step «rounds» through 0, 1, 2, 3, 4. The "bits different" readout goes 1, 3, 9, 5, 5 out of 16: one flipped bit spreads over the block. -3. With «rounds» at 4, set «flip» to 8, then to 15. A different input bit now differs, and the readout shows 7 / 16, then 6 / 16 — the change spreads no matter which bit you pick. +1. Look at the top stage: message A is the word "hi" and message B is "Hi". The capital letter changes just one of the 16 bits, and a red column marks it. +2. Keep «flip» at 2 and step «rounds» through 0, 1, 2, 3, 4. The "bits different" readout goes 1, 2, 6, 8, 8 out of 16: one flipped bit spreads until half the block differs. +3. With «rounds» at 4, set «flip» to 10, then to 15. B becomes "hI", then "hh", and the readout shows 11 / 16, then 8 / 16 — the change spreads no matter which bit you pick. ## Real-life examples -1. **Sending a block with zero rounds.** «rounds» = 0 skips all mixing, so A and B — identical except for one input bit — still differ by exactly that one square at the bottom, just like plain, unshuffled data. -2. **A partly-mixed message.** «rounds» = 2 already spreads that one-bit difference to 9 of the 16 squares, but after so few rounds the pattern is still easy to predict, the way a weak, watered-down cipher would leave it. -3. **A fully-mixed message, from a different bit.** «rounds» = 4 with «flip» = 8 shows a different starting bit still ending up scrambling roughly half the block, just as real AES's 10 rounds do to a full 128-bit block. +1. **Sending a block with zero rounds.** «rounds» = 0 skips all mixing, so A and B — identical except for one input bit — still differ by exactly one red column, just like plain, unshuffled data. +2. **A partly-mixed message.** «rounds» = 2 already spreads that one-bit difference to 6 of the 16 bits, but after so few rounds the pattern is still easy to predict, the way a weak, watered-down cipher would leave it. +3. **A fully-mixed message, from a different bit.** «rounds» = 4 with «flip» = 3 (B is "xi") shows a different starting bit still ending up scrambling half the block, 8 of 16, just as real AES's 10 rounds do to a full 128-bit block. ## Test yourself 1. Push «rounds» to 4, the most this toy cipher offers. 2. Push «flip» to 15, the very last input bit. -3. Set «rounds» to 4 and «flip» back to 0, and count how many of the 16 bottom squares differ between A and B. +3. Set «rounds» to 4 and «flip» back to 2, and count how many of the 16 bits in the last stage differ between A and B. ## Intuition -Take a tiny 16-bit block of data, small enough to draw completely on screen, and flip just one of its bits before encrypting both the original and the flipped copy side by side. The left tower of small squares is block A, the right tower is block B, identical to A except for one bit chosen with the «flip» slider. Drag «rounds» from 0 to 4 and watch a fresh row appear for each round: at «rounds» = 0 the two towers still differ by exactly one square, but every round mixes in the key, swaps each group of 4 bits through a fixed lookup table, and shuffles all 16 bits into new positions. +Take a tiny 16-bit block of data, the two letters "hi", small enough to draw completely on screen, and flip just one of its bits before encrypting both the original and the flipped copy side by side. In each stage of the picture block A sits above block B, identical to A except for one bit chosen with the «flip» slider, and a red column marks every bit where they differ. Drag «rounds» from 0 to 4 and watch one more stage fill in for each round: at «rounds» = 0 the two blocks still differ by exactly one bit, but every round mixes in the key, swaps each group of 4 bits through a fixed lookup table, and shuffles all 16 bits into new positions. -By the last row at «rounds» = 4, roughly half of the 16 squares between A and B differ in color, even though A and B started only one bit apart — this spreading is exactly what real AES does at a larger scale, encrypting a full block as $C = E_K(M)$, a message $M$ scrambled by repeated rounds under key $K$. +By the last stage at «rounds» = 4, about half of the 16 bits of A and B differ (8 of 16 at the starting settings), even though A and B started only one bit apart — this spreading is exactly what real AES does at a larger scale, encrypting a full block as $C = E_K(M)$, a message $M$ scrambled by repeated rounds under key $K$. ## Formal diff --git a/content/lessons/cryptography/block-ciphers-and-aes/lesson.yaml b/content/lessons/cryptography/block-ciphers-and-aes/lesson.yaml index 7307346..fe03a77 100644 --- a/content/lessons/cryptography/block-ciphers-and-aes/lesson.yaml +++ b/content/lessons/cryptography/block-ciphers-and-aes/lesson.yaml @@ -26,7 +26,7 @@ parameters: min: 0 max: 15 step: 1 - value: 0 + value: 2 key: min: 0 max: 65535 @@ -45,13 +45,13 @@ charts: [] primary: rounds presets: - rounds: 0 - flip: 0 + flip: 2 key: 14996 - rounds: 2 - flip: 0 + flip: 2 key: 14996 - rounds: 4 - flip: 8 + flip: 3 key: 14996 challenges: - check: rounds diff --git a/content/ui/ar.yaml b/content/ui/ar.yaml index 8cb4cdb..b635b35 100644 --- a/content/ui/ar.yaml +++ b/content/ui/ar.yaml @@ -722,11 +722,13 @@ hash.hint: غيّر حرفًا واحدًا فينقلب نحو نصف البت hash.unavailable: لا يستطيع هذا المتصفح حساب SHA-256 هنا spn.rounds: الجولات spn.different: البتات المختلفة -spn.hint: مدخلان يختلفان في بت واحد، يُشفّران جنبًا إلى جنب -spn.input: المدخل +spn.hint: رسالتان تختلفان في بت واحد، نشفّرهما بالمفتاح نفسه. كل صف من المربعات 16 بتًا. +spn.input: الرسالة spn.after: بعد الجولة {r} -spn.bits: بتات مختلفة -spn.aes: يكرر AES الخطوات الثلاث نفسها على 128 بت من 10 إلى 14 مرة، مع صندوق استبدال أكبر +spn.step: 'الجولة {r}: نمزج المفتاح، ثم نبدّل كل 4 بتات من جدول، ثم نعيد ترتيب البتات' +spn.half: النصف +spn.legend: العمود الأحمر بت يختلف فيه A عن B. في الكتلة الممزوجة جيدًا يختلف نحو نصف البتات، أي 8 من 16. +spn.aes: وAES الحقيقي يكرر الخطوات الثلاث نفسها على 128 بتًا، من 10 إلى 14 مرة، بجدول أكبر. ec.off: ليس على المنحنى هنا ec.warning: تنبيه ec.singular: للمنحنى نقطة حادة diff --git a/content/ui/en.yaml b/content/ui/en.yaml index 426bdf0..94d2c96 100644 --- a/content/ui/en.yaml +++ b/content/ui/en.yaml @@ -722,11 +722,13 @@ hash.hint: change one letter and about half of the 256 bits flip hash.unavailable: this browser cannot compute SHA-256 here spn.rounds: rounds spn.different: bits different -spn.hint: two inputs that differ in one bit, encrypted side by side -spn.input: input +spn.hint: Two messages one bit apart, encrypted with the same key. Each row of squares is 16 bits. +spn.input: the message spn.after: after round {r} -spn.bits: bits differ -spn.aes: AES does the same three steps on 128 bits, 10 to 14 times, with a bigger S-box +spn.step: 'round {r}: mix in the key, swap each group of 4 bits from a table, shuffle the bits' +spn.half: half +spn.legend: A red column is a bit where A and B differ. A well-mixed block has about half of its bits different, 8 of 16. +spn.aes: Real AES does the same three steps on 128 bits, 10 to 14 times, with a bigger table. ec.off: not on the curve here ec.warning: warning ec.singular: curve has a sharp point diff --git a/src/viz/cryptography/ToySPN.vue b/src/viz/cryptography/ToySPN.vue index 7ac5a28..cc694ae 100644 --- a/src/viz/cryptography/ToySPN.vue +++ b/src/viz/cryptography/ToySPN.vue @@ -1,50 +1,83 @@