Data integrity
การรักษาความถูกต้องของข้อมูล
- ความสมบูรณ์ หมายความว่าข้อมูลยังคงแม่นยำ เทคนิคสองอย่างปกป้องมัน: การตรวจสอบความถูกต้อง และ การตรวจสอบความถูกต้อง
- พวกมันฟังดูคล้ายกันแต่ทำหน้าที่ต่างกัน — เป็นข้อแตกต่างคลาสสิกในข้อสอบ
Validation vs Verification
- Validation ตรวจสอบว่าข้อมูล สมเหตุสมผล ขณะป้อน ตัวอย่าง:
- Range check (อายุ 0–120), length check (เบอร์โทรศัพท์), format check (อีเมลมี
@), presence check (ไม่เว้นว่าง)
- Range check (อายุ 0–120), length check (เบอร์โทรศัพท์), format check (อีเมลมี
- Verification ตรวจสอบว่าข้อมูลถูก คัดลอกอย่างถูกต้อง ตัวอย่าง:
- Double entry (พิมพ์รหัสผ่านสองครั้ง) หรือ visual check (อ่านออกเสียงอีกครั้ง)
ตรวจสอบข้อมูลระหว่างส่ง
- เมื่อข้อมูลเดินทาง บิตอาจเปลี่ยน checksum หรือ check digit จะจับได้
- ผู้ส่งคำนวณตัวเลขเล็กจากข้อมูล ผู้รับคำนวณใหม่ หากต่างกัน ข้อมูลเสียหาย
number = "1389"
print(sum(int(d) for d in number) % 10) # a one-digit checksum
ถึงเวลาฝึกฝน
- คำนวณ check digit แบบง่ายโดยการบวกเลขทุกหลัก mod 10 ระบบจริง (เช่น บาร์โค้ดและ ISBN) ใช้แนวคิดนี้ที่ซับซ้อนกว่า
ครอบคลุม: A-Level 6.2 (validation/verification), IGCSE 2.2 (error detection).
ข้อผิดพลาดที่พบบ่อย
- Checksum หรือ check digit ตรวจจับการเปลี่ยนแปลงที่ไม่ตั้งใจต่อข้อมูล
- Validation ตรวจสอบว่าข้อมูลสมเหตุสมผล; Verification ตรวจสอบว่าป้อนถูกต้อง
Hashes detect tampering
Re-hash the data and compare: any change flips the digest.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A simple checksum helps catch typing errors. Add up the digits of number and take the result modulo 10. Print that single check digit.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Now be the receiver. The sender transmitted the digits with check digit 8, but one digit got corrupted on the way. Recompute the checksum of received and print ERROR if it does not equal sent_check, else OK.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A parity bit is another integrity check. With even parity, the extra bit makes the total number of 1s even. Write parity_bit(bits), which takes a string such as "1011001" and returns "0" หรือ "1".
คลิก Run เพื่อดูผลลัพธ์ที่นี่