Data integrity · ความสมบูรณ์ของข้อมูล
Keeping data correct
- Integrity means data stays accurate. Two techniques protect it: validation and verification.
- They sound similar but do different jobs — a classic exam distinction.
การรักษาความถูกต้องของข้อมูล
- ความสมบูรณ์ หมายความว่าข้อมูลยังคงแม่นยำ เทคนิคสองอย่างปกป้องมัน: การตรวจสอบความถูกต้อง และ การตรวจสอบความถูกต้อง
- พวกมันฟังดูคล้ายกันแต่ทำหน้าที่ต่างกัน — เป็นข้อแตกต่างคลาสสิกในข้อสอบ
Validation vs verification
- Validation checks data is reasonable as it is entered. Examples:
- Range check (age 0–120), length check (a phone number), format check (an email has an
@), presence check (not left blank).
- Range check (age 0–120), length check (a phone number), format check (an email has an
- Verification checks data was copied correctly. Examples:
- Double entry (type a password twice), or a visual check (read it back).
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 (อ่านออกเสียงอีกครั้ง)
Checking data in transit
- When data travels, bits can flip. A checksum or check digit catches that.
- The sender calculates a small number from the data; the receiver recalculates it. If they differ, the data was corrupted.
ตรวจสอบข้อมูลระหว่างส่ง
- เมื่อข้อมูลเดินทาง บิตอาจเปลี่ยน checksum หรือ check digit จะจับได้
- ผู้ส่งคำนวณตัวเลขเล็กจากข้อมูล ผู้รับคำนวณใหม่ หากต่างกัน ข้อมูลเสียหาย
number = "1389"
print(sum(int(d) for d in number) % 10) # a one-digit checksum
Your turn
- Compute a simple check digit by summing the digits modulo 10. Real systems (like barcodes and ISBNs) use cleverer versions of this idea.
Covers: A-Level 6.2 (validation/verification), IGCSE 2.2 (error detection).
ถึงเวลาฝึกฝน
- คำนวณ check digit แบบง่ายโดยการบวกเลขทุกหลัก mod 10 ระบบจริง (เช่น บาร์โค้ดและ ISBN) ใช้แนวคิดนี้ที่ซับซ้อนกว่า
ครอบคลุม: A-Level 6.2 (validation/verification), IGCSE 2.2 (error detection).
Common mistakes
- A checksum or check digit spots accidental changes to data.
- Validation checks data is sensible; verification checks it was entered correctly.
ข้อผิดพลาดที่พบบ่อย
- Checksum หรือ check digit ตรวจจับการเปลี่ยนแปลงที่ไม่ตั้งใจต่อข้อมูล
- Validation ตรวจสอบว่าข้อมูลสมเหตุสมผล; Verification ตรวจสอบว่าป้อนถูกต้อง
Hashes detect tampering · แฮชตรวจจับการแก้ไข
Re-hash the data and compare: any change flips the digest. · แฮชข้อมูลใหม่และเปรียบเทียบ: การเปลี่ยนแปลงใดๆ จะทำให้ นิรภัย เปลี่ยนแปลง
A simple checksum helps catch typing errors. Add up the digits of number and take the result modulo 10. Print that single check digit. · checksum แบบง่ายช่วยจับข้อผิดพลาดในการพิมพ์ บวกตัวเลขทั้งหมดของ number แล้วนำผลหารด้วยโมดูลัส 10. พิมพ์เลขตรวจสอบ这一个 digit นี้
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
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. · ตอนนี้角色扮演ผู้รับ. ผู้ส่งส่งตัวเลขมาพร้อมเลขตรวจสอบ 8, แต่หนึ่งตัวเลขเสียหายระหว่างทาง คำนวณ checksum ใหม่ของ received และพิมพ์ ERROR หากไม่เท่ากับ sent_check, ถ้าไม่ก็พิมพ์ OK
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่