التشفير المتماثل
Locking with a key
- Encryption scrambles a message so only someone with the key can read it.
- In symmetric encryption, the same key locks and unlocks. Sender and receiver must both know it.
The Caesar cipher
- The oldest example: shift every letter forward by a fixed number. With shift 3,
a → d,b → e, and so on. - The key is the shift. Decrypting just shifts back.
text = "attack"
shift = 3
out = "".join(chr((ord(c) - 97 + shift) % 26 + 97) for c in text)
print(out) # dwwdfn
Why Caesar is weak
- There are only 25 possible shifts, so a computer can try them all in a blink.
- This is a brute-force attack on the key — exactly what real encryption must resist.
What real ciphers do
- Modern symmetric ciphers like AES use 128-bit or longer keys: 2¹²⁸ is about 3 × 10³⁸ possible keys, far too many to try one by one.
- The big problem they leave: how do two people share the secret key safely? The next lesson solves it.
Covers: IGCSE 2.3 (symmetric encryption), A-Level 17.1.
Common mistakes
- One shared key both encrypts and decrypts.
- The hard part is sharing that key safely.
التشفير المتماثل
يستخدم كسر قيصر مفتاح مشترك واحد للتشفير وفك التشفير.
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
شفّر hello باستخدام كسر قيصر: إزاحة كل حرف للأمام بمقدار shift أماكن (التفاف بعد z العودة إلى a). ابنِ السلسلة المشفرة وطبعها.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
الآن يكسرها — وهذا سبب ضعف قيصر. لقد اعتذرت عن cipher، وتشك في أن النص الأصلي هو attack. جرب كل إزاحة من 1 إلى 25، بإزاحة للخلف، وطبع الإزاحة التي تحول cipher إلى attack.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
المستقبل يعرف المفتاح، لذا يمكنه عكس الإزاحة. اكتب decrypt(text, shift) الذي يحرك كل حرف صغير للخلف بمقدار shift (مع التفاف من a إلى z) ويترك المسافات والأحرف الأخرى دون تغيير.
اضغط تشغيل لرؤية المخرجات هنا.