Data integrity — validation and verification · 数据完整性 — 验证和核实
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| integrity/ɪnˈteɡrɪti/ | 完整性 | wán zhěng xìng |
| validation/ˌvælɪˈdeɪʃn/ | 验证 | yàn zhèng |
| verification/ˌverɪfɪˈkeɪʃn/ | 核对 | hé duì |
| range check/reɪndʒ tʃek/ | 范围检查 | fàn wéi jiǎn chá |
| check digit/tʃek ˈdɪdʒɪt/ | 校验位 | jiào yàn wèi |
| double entry/ˈdʌbl ˈentri/ | 双重录入 | shuāng chóng lù rù |
| parity check/ˈpærɪti tʃek/ | 奇偶校验 | jī ǒu jiào yàn |
| checksum/ˈtʃeksəm/ | 校验和 | jiào yàn hé |
| cyclic redundancy check/ˈsaɪklɪk rɪˈdʌndənsi tʃek/ | 循环冗余校验 | xún huán rǒng yú jiào yàn |
| parity block check/ˈpærɪti blɒk tʃek/ | 奇偶块校验 | jī ǒu kuài jiào yàn |
Every number passed every check
- In September 1999 NASA's Mars Climate Orbiter fired its engine to enter orbit and was never heard from again. It had flown 170 km lower than planned and burned up.
- One team's software produced thrust figures in pound-force seconds; the receiving software expected newton-seconds. Every value was a well-formed number in a sensible range. Every value was wrong by a factor of 4.45.
- No format check could have caught it, because the data was not malformed. It was simply not what it claimed to be. $327 million.
- This lesson is the two families of checks that guard integrity 完整性: validation, which asks whether data is sensible, and verification, which asks whether it was copied correctly. And the gap between them that Mars fell through.
每个数字都通过了每项检查
- 1999 年 9 月,NASA 的火星气候探测者号点燃发动机准备进入轨道,之后再也没有消息。它比计划低飞了 170 公里,烧毁了。
- 一个团队的软件以磅力·秒输出推力数据;接收方的软件期待的是牛顿·秒。每个值都是格式正确、范围合理的数字。每个值都错了 4.45 倍。
- 没有任何格式检查能抓到它,因为数据并没有畸形。它只是不是它声称的那个东西。3.27 亿美元。
- 这一课讲守护完整性(integrity)的两类检查:问数据是否合理的验证,和问数据是否正确复制的核对。还有火星从中掉落的那道缝。
Two questions
- Data has integrity when it is accurate, consistent and complete.
- Validation 验证 is an automatic check that entered data is reasonable and follows set rules. It asks: is this sensible?
- Verification 核对 checks that data has been entered or transferred correctly, by comparing it with the source or with a recomputed value. It asks: was this copied correctly?
- Neither proves the data is true. Both are needed.
两个问题
- 数据准确、一致、完整时,就具有完整性。
- 验证(validation)是自动检查输入的数据是否合理、是否遵循设定规则。它问:这合理吗?
- 核对(verification)通过与来源或重新计算的值比较,检查数据是否被正确输入或传输。它问:这被正确复制了吗?
- 两者都不能证明数据为真。两者都需要。
Computing concept lab · 计算概念实验
Classify concrete examples by the computing idea they demonstrate. · 根据它们所演示的计算概念对具体示例进行分类。
Validation methods
| Check | Rule | Example |
|---|---|---|
| range check 范围检查 | between two limits | a month is 1 to 12 |
| limit check | on one side of a single limit | age ≥ 18 |
| existence (lookup) check | the value is in a list or table | the product code exists |
| length check | the right number of characters | a postcode of 6 characters |
| type / character check | the right kind of data | a phone field allows only digits |
| format check | matches a pattern | an email contains @ |
| presence check | required fields are not empty | a name is entered |
| check digit 校验位 | an extra digit computed from the others | ISBNs, card numbers |
验证方法
| 检查 | 规则 | 例子 |
|---|---|---|
| 范围检查(range check) | 在两个界限之间 | 月份是 1 到 12 |
| 界限检查(limit check) | 在单一界限的一侧 | 年龄 ≥ 18 |
| 存在性检查(existence check,查表) | 值在列表或表中 | 商品代码存在 |
| 长度检查(length check) | 字符数正确 | 6 个字符的邮编 |
| 类型/字符检查(type check) | 数据种类正确 | 电话字段只允许数字 |
| 格式检查(format check) | 匹配一个模式 | 电子邮件包含 @ |
| 存在检查(presence check) | 必填字段不为空 | 输入了姓名 |
| 校验位(check digit) | 由其他位算出的额外一位 | ISBN、卡号 |
Checking that a month entered is between 1 and 12 is a: · 检查输入的月份是否在 1 到 12 之间属于:
A range check confirms a value lies within sensible limits. · 范围检查确认值位于合理范围内。
Match each validation check to its purpose. · 将每种验证检查与其用途匹配。
Presence = not empty; format = matches a pattern; check digit = computed to catch mistyped digits. · 存在性 = 非空;格式 = 符合模式;校验位 = 计算得出以捕获误触的数字。
An extra digit computed from the others to catch a mistyped number (as on ISBNs and card numbers) is a ______ digit. · 根据其他数字计算出的额外数字用于捕获误触的数字(如 ISBN 号和卡号),这被称为______位。
A check digit is recomputed from the rest and compared, catching most single-digit and transposition errors. · 校验位会根据其余部分重新计算并进行比较,捕获大多数单数字和交换错误。
Worked example: name the check the pseudocode performs
| Pseudocode | Check |
|---|---|
IF x < 0 OR x > 10 THEN OUTPUT "Invalid" |
range check: between two limits |
IF x = "" THEN OUTPUT "Invalid" |
presence check: not empty |
IF NOT(x = "Red" OR x = "Yellow" OR x = "Blue") THEN OUTPUT "Invalid" |
existence (lookup) check: one of a list |
IF LENGTH(x) <> 6 THEN OUTPUT "Invalid" |
length check: six characters |
IF MID(x, 1, 1) < "A" OR MID(x, 1, 1) > "Z" THEN OUTPUT "Invalid" |
format check: the first character is a letter |
- A car registration of one letter, three digits and two letters needs a format check on each position and a length check for six characters. A date of birth needs a format check (
DD/MM/YYYY), a range check (the month is 1 to 12, the year not in the future) and a presence check.
例题:说出伪代码执行的检查
| 伪代码 | 检查 |
|---|---|
IF x < 0 OR x > 10 THEN OUTPUT "Invalid" |
范围检查:在两个界限之间 |
IF x = "" THEN OUTPUT "Invalid" |
存在检查:不为空 |
IF NOT(x = "Red" OR x = "Yellow" OR x = "Blue") THEN OUTPUT "Invalid" |
存在性(查表)检查:列表中的一个 |
IF LENGTH(x) <> 6 THEN OUTPUT "Invalid" |
长度检查:六个字符 |
IF MID(x, 1, 1) < "A" OR MID(x, 1, 1) > "Z" THEN OUTPUT "Invalid" |
格式检查:第一个字符是字母 |
- 一个字母、三个数字、两个字母的车牌号需要对每个位置做格式检查,并做六个字符的长度检查。出生日期需要格式检查(
DD/MM/YYYY)、范围检查(月份 1 到 12,年份不在未来)和存在检查。
Match each line of pseudocode to the validation check it performs. · 将每行伪代码与其执行的验证检查匹配。
Empty test = presence; character count = length; two limits = range; a list of allowed values = existence or lookup. · 空值测试 = 存在性;字符计数 = 长度;两个限制 = 范围;允许值的列表 = 存在性或查找。
Worked example: a check digit, and what it misses
- A simple scheme: the check digit is the remainder when the digit sum is divided by 10, appended to the number.
4162has digit sum 13, so it is stored as41623. - A user types
41523: the sum is now 12, the check digit should be 2, so the error is caught. - A user types
14623: the first two digits are swapped, but the sum is still 13, so the check digit matches and the error is not caught. Real schemes (ISBN, card numbers) weight each position so that a swap changes the result.
例题:校验位,以及它漏掉的
- 一个简单方案:校验位是各位数字之和除以 10 的余数,附加在数字后面。
4162的数字和是 13,所以存为41623。 - 用户输入
41523:数字和现在是 12,校验位应为 2,所以错误被抓到。 - 用户输入
14623:前两位交换了,但数字和仍是 13,所以校验位匹配,错误没被抓到。真实方案(ISBN、卡号)给每个位置加权,使交换会改变结果。
What validation cannot do
- Validation catches data that is wrongly formatted or out of range.
- It cannot catch data that has the right format and is factually wrong.
Bobtyped forBibpasses every check; so did every thrust figure sent to Mars. - For that you need verification against the source, and a person who reads what they typed.
验证做不到的
- 验证抓住格式错误或超出范围的数据。
- 它抓不住格式正确但事实错误的数据。把
Bib打成Bob通过所有检查;发往火星的每个推力数据也是如此。 - 那需要与来源核对,以及一个会读自己输入内容的人。
Why can validation still let bad data through? · 为什么验证仍可能让错误数据通过?
Validation checks the form, not the truth — a correctly formatted but wrong value passes. · 验证检查形式而非真实性 — 格式正确但数值错误的值可以通过。
Verification during data entry
- Double entry 双重录入: the data is entered twice, by the same person or by two people, and the computer compares the two versions and reports any difference. A new password is the everyday case.
- Visual check: the person compares what is on the screen with the original source document and corrects any difference before saving.
- Both protect integrity by making sure the stored data matches the source.
数据输入时的核对
- 双重录入(double entry):数据被输入两次——由同一个人或两个人——计算机比较两个版本并报告任何差异。新密码是日常的例子。
- 目视检查(visual check):人把屏幕上的内容与原始来源文件比较,在保存前纠正任何差异。
- 两者都通过确保存储的数据与来源一致来保护完整性。
Asking a user to type a new password twice is an example of: · 要求用户两次输入新密码是以下哪一项的例子:
Double entry compares two typed copies to verify the data was entered correctly. · 双重输入比较两份键入副本以验证数据是否正确输入。
Verification during data transfer
- Bits can flip in transit. A parity check 奇偶校验 adds one extra bit to each byte so that the number of 1s is even (even parity) or odd; the receiver recounts, and a single flipped bit fails the count.
- A checksum 校验和 is a value calculated from a block of data by an algorithm and sent with it; the receiver recalculates it and compares. Transferring video files from a camera to a server works this way: a mismatch means retransmit.
- A cyclic redundancy check 循环冗余校验 (CRC) is a stronger checksum using polynomial division, catching many more error patterns.
One extra bit makes the count of 1s even; a flipped bit breaks it
Compute, send, recompute, compare
数据传输时的核对
- 位在传输中可能翻转。奇偶校验(parity check)给每个字节加一个额外位,使 1 的个数为偶数(偶校验)或奇数;接收者重新计数,单个翻转的位会让计数出错。
- 校验和(checksum)是用算法从一块数据算出并随数据发送的值;接收者重新计算并比较。把视频文件从相机传到服务器就是这样:不匹配意味着重传。
- 循环冗余校验(cyclic redundancy check,CRC)是用多项式除法的更强校验和,能抓住更多错误模式。

一个额外位让 1 的个数为偶数;翻转一位就打破它

计算、发送、重算、比较
A parity check works by: · 奇偶校验的工作原理是:
The parity bit makes the count of 1s even or odd; the receiver re-counts to detect a single-bit error. · 奇偶校验位使 1 的数量为偶数或奇数;接收端重新计数以检测单比特错误。
Which are verification methods used during data transfer? Select all · 所有 that apply. · 哪些是在数据传输期间使用的验证方法?选择所有适用项。
Parity and checksums recompute a value at the receiving end. Double entry and a visual check happen during data entry. · 奇偶校验和校验和在接收端重新计算值。双重输入和视觉检查发生在数据输入期间。
A byte parity check detects every possible transmission error in that byte. · 字节奇偶校验可以检测到该字节中所有可能的传输错误。
Two flipped bits leave the count of 1s unchanged, so they pass. Parity reliably catches single-bit errors only. · 两个翻转的比特使 1 的数量保持不变,因此它们会通过。奇偶校验仅可靠地捕获单比特错误。
Worked example: a parity block locates the bit
- A parity block check 奇偶块校验 arranges the bytes in a grid: each byte carries a row parity bit, and one extra parity byte holds the column parity of the bytes above it.
- Four bytes are sent with even parity, followed by the parity byte. Count the 1s in every row and column: byte 3 has five and column 4 has three, both odd.
- The bit where that row and that column cross is the one that changed, so it is reset from 1 to 0. A single parity bit detects an error; a block locates and corrects it.
One row wrong, one column wrong: the bit is at the crossing
例题:奇偶块定位那一位
- 奇偶块校验(parity block check)把字节排成网格:每个字节带一个行校验位,再有一个额外的校验字节保存上方各字节的列校验。
- 四个字节以偶校验发送,后跟校验字节。数每行每列的 1:字节 3 有五个,第 4 列有三个,都是奇数。
- 那一行与那一列交叉处的位就是改变了的位,所以把它从 1 重置为 0。单个校验位能检测错误;一个块能定位并纠正它。

一行错、一列错:那一位就在交叉点
Put the steps of a parity block check in order. · 按顺序排列奇偶校验块检查的步骤。
Rows detect, columns detect, the crossing locates, and the flip corrects. That is what a block adds over a single parity bit. · 行检测,列检测,交叉点定位,翻转修正。这就是块校验相比单个奇偶校验位的优势。
Worked example: which check catches which error
- A user types their date of birth as
31/02/2009, then types their email address twice. Which check catches which error, and what is the difference? - Validation: a format or range check rejects
31/02/2009, because February never has 31 days. The computer tests the value against a rule. - Verification: double entry compares the two email addresses and reports a mismatch if they differ. The computer compares two copies, and it would accept a wrong address typed identically twice.
- Validation asks whether the data is sensible; verification asks whether it was entered correctly.
Sensible, or copied correctly: two different questions
例题:哪项检查抓到哪个错误
- 用户把出生日期输入为
31/02/2009,然后把电子邮件地址输入两次。哪项检查抓到哪个错误,区别是什么? - 验证:格式或范围检查拒绝
31/02/2009,因为二月从来没有 31 天。计算机把值与规则比对。 - 核对:双重录入比较两个电子邮件地址,不同就报告不匹配。计算机比较两份副本,而且两次输入同样错误的地址它会接受。
- 验证问数据是否合理;核对问数据是否被正确输入。

合理,还是正确复制:两个不同的问题
Which statement is correct? · 哪项陈述是正确的?
Validation tests sensibility against rules; verification tests that the data was entered/transferred without change. · 验证根据规则测试合理性;验证测试数据在输入/传输过程中是否未发生改变。
Verification proves the data was copied or entered without change — but not that the value is factually correct. · 验证证明数据在复制或输入时未发生改变 — 但不证明该值在事实上是正确的。
Double entry / checksums prove the data arrived unchanged; only a human or a cross-check can confirm it is actually true. · 双重输入/校验和证明数据到达时未改变;只有人工或交叉检查才能确认其实际上是真实的。
Marks that slip away
- A check digit is validation on entry; parity and a checksum verify a transfer. Do not file them under the wrong heading.
- Neither check proves the data is true. Validation says "reasonable"; verification says "matches the source".
- A byte parity check misses two flipped bits in the same byte, because they cancel. Say "single-bit errors".
- Encryption is a security measure. It does nothing for integrity.
容易丢掉的分
- 校验位是输入时的验证;奇偶校验和校验和核对传输。不要归到错误的标题下。
- 两种检查都不能证明数据为真。验证说"合理";核对说"与来源一致"。
- 字节奇偶校验漏掉同一字节中两个翻转的位,因为它们互相抵消。要说"单比特错误"。
- 加密是安全措施。它对完整性毫无作用。
You've got it
- validation = automatic rules on entry: range, limit, existence, length, type, format, presence, check digit; it cannot catch right-format-but-wrong values
- verification on entry = double entry and a visual check; on transfer = parity (byte or block), checksum, CRC
- a parity block locates a flipped bit at the crossing of the failing row and column
- validation asks "sensible?"; verification asks "copied correctly?"; neither asks "true?"
你掌握了
- 验证 = 输入时的自动规则:范围、界限、存在性、长度、类型、格式、存在、校验位;它抓不住格式正确但内容错误的值
- 输入时的核对 = 双重录入和目视检查;传输时 = 奇偶校验(字节或块)、校验和、CRC
- 奇偶块在出错行与出错列的交叉点定位翻转的位
- 验证问"合理吗?";核对问"复制正确吗?";两者都不问"是真的吗?"