Symmetric encryption
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.
ล็อคด้วยกุญแจ
- การเข้ารหัส สุ่มข้อมูลให้เพียงผู้ที่มี กุญแจ เท่านั้นที่อ่านได้
- ในการ เข้ารหัสแบบสมมาตร (symmetric) กุญแจเดียวกัน ใช้ล็อคและปลดล็อก ผู้ส่งและผู้รับต้องรู้ทั้งสองฝ่าย
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.
รหัสซีซาร์
- ตัวอย่างที่เก่าแก่ที่สุด: เลื่อนตัวอักษรทุกตัวไปข้างหน้าตามจำนวนคงที่ เช่น เลื่อน 3 ตำแหน่ง จะได้
a → d,b → eและอื่นๆ - กุญแจ คือจำนวนการเลื่อน การถอดรหัสก็แค่เลื่อนถอยหลัง
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.
ทำไมรหัสซีซาร์จึงอ่อนแอ
- มีเพียง 25 การเลื่อนที่เป็นไปได้ คอมพิวเตอร์จึงลองทั้งหมดได้ในพริบตา
- นี่คือ brute-force attack บนกุญแจ — ซึ่ง正是 what real encryption must resist
What real ciphers do
- Modern symmetric ciphers like AES use keys with billions of billions of possibilities.
- 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.
สิ่งที่erequisitesจริงทำงานได้
- CODECIPHER แบบสมมาตรสมัยใหม่อย่าง AES ใช้กุญแจที่มีความเป็นไปได้นับล้านล้าน
- ปัญหาใหญ่ที่ยังเหลืออยู่: จะทำอย่างไรให้สองคนแบ่งปันกุญแจลับได้อย่างปลอดภัย? บทเรียนถัดไปจะแก้ปัญหานี้
ครอบคลุม: IGCSE 2.3 (การเข้ารหัสแบบสมมาตร), A-Level 17.1.
Common mistakes
- One shared key both encrypts and decrypts.
- The hard part is sharing that key safely.
ข้อผิดพลาดที่พบบ่อย
- กุญแจร่วมกันตัวเดียวใช้ทั้งเข้ารหัสและถอดรหัส
- ส่วนที่ยากคือการแบ่งปันกุญแจนั้นอย่างปลอดภัย
Symmetric encryption
The Caesar cipher uses one shared key to encrypt and decrypt. · Caesar cipher ใช้ คีย์ร่วมกันเดียว เพื่อ encrypt และ decrypt
Encrypt hello with a Caesar cipher: shift each letter forward by shift places (wrapping past z back to a). Build the encrypted string and print it. · Encrypt hello ด้วย Caesar cipher: เลื่อนแต่ละตัวอักษรไปข้างหน้า shift ตำแหน่ง (wrap ผ่าน z กลับไปที่ a). สร้าง string yang已被encrypted และพิมพ์มัน
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Now break it — that is why Caesar is weak. You intercepted cipher, and you suspect the plaintext is attack. Try every shift from 1 to 25, shifting back, and print the shift that turns cipher into attack. · ตอนนี้ทำลายมัน — นั่นคือเหตุผลที่ Caesar อ่อนแอ คุณ intercept cipher, และคุณสงสัยว่า plaintext คือ attack. ลองทุก shift จาก 1 ถึง 25, shift ถอย, และพิมพ์ shift yangเปลี่ยน cipher เป็น attack
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่