algorithm · 2025-03-10 · 5 min read

The transposition Luhn cannot catch — and the algorithms that can

Luhn detects every single-digit error and most adjacent swaps — except one specific pair, plus a family of twin errors. Here is the math and the stronger alternatives.

Most swaps change the sum — one pair does not.
Most swaps change the sum — one pair does not. — © Tibe De Kort · Pexels

Swapping two adjacent digits changes which one gets doubled in the Luhn procedure. For almost all pairs this changes the sum and the error is caught. There is exactly one exception among adjacent pairs — and you can reproduce it with the 'swap two adjacent digits' button in the Luhn lab.

The 09 ↔ 90 blind spot

Doubling 9 gives 18 → 1 + 8 = 9. Doubling 0 gives 0. So the pair contributes 9 + 0 = 9 whether it reads 09 or 90, and the total is unchanged. Every other adjacent transposition (e.g. 12 ↔ 21) alters the sum by a non-multiple of 10 and is detected.

Twin errors

Luhn also misses some twin substitutions in the doubled position: 22 ↔ 55, 33 ↔ 66 and 44 ↔ 77, because 2·2 = 4 and 2·5 = 10 → 1 both end up contributing values that differ by a multiple of 10 once the neighbouring digit is included. These are rarer in practice than single-digit slips, which is why Luhn's coverage was considered good enough for keypunch operators in the 1950s — see a short history of Luhn.

Stronger schemes

  • The Verhoeff algorithm (1969) uses the dihedral group D5 and catches all single-digit errors and all adjacent transpositions.
  • The Damm algorithm (2004) achieves the same with a simpler quasigroup table and no special-casing.
  • ISO 7064 defines several mod-11 and mod-97 variants used in IBANs and ISBNs.
Payment networks never switched because the installed base is enormous, Luhn is good enough for its narrow purpose, and the real security lives in authorization — not in the check digit.
Verhoeff and Damm catch more, but Luhn won on simplicity.
Verhoeff and Damm catch more, but Luhn won on simplicity.

Keywords: Luhn limitations, transposition error, Verhoeff algorithm, Damm algorithm, check digit comparison, 09 90 swap

Frequently asked questions

Which error does Luhn fail to detect?

Swapping adjacent 0 and 9 (09 ↔ 90), and some twin substitutions such as 22 ↔ 55 in the doubled position.

Is there a better check digit than Luhn?

Yes — Verhoeff and Damm detect all single-digit errors and all adjacent transpositions, but card networks keep Luhn for compatibility.

On this site

External references

Related articles

التبديل الذي لا تستطيع لون كشفه — والخوارزميات التي تستطيع — النسخة العربية

تكشف لون كل أخطاء الخانة الواحدة ومعظم تبديلات الخانات المتجاورة — إلا زوجًا واحدًا بعينه، وعائلة من الأخطاء التوأمية. إليك الرياضيات والبدائل الأقوى.

تبديل خانتين متجاورتين يغيّر أيّهما تُضاعَف في إجراء لون. وفي كل الأزواج تقريبًا يغيّر هذا المجموع فيُكتشف الخطأ. يوجد استثناء واحد بالضبط بين الأزواج المتجاورة — ويمكنك إعادة إنتاجه بزر «بدّل خانتين متجاورتين» في مختبر لون.

النقطة العمياء 09 ↔ 90

مضاعفة 9 تعطي 18 → 1 + 8 = 9. ومضاعفة 0 تعطي 0. فيضيف الزوج 9 + 0 = 9 سواء قُرئ 09 أو 90، ويبقى المجموع دون تغيير. كل تبديل متجاور آخر (مثل 12 ↔ 21) يغيّر المجموع بغير مضاعفات 10 فيُكتشف.

الأخطاء التوأمية

تفوّت لون أيضًا بعض استبدالات التوأم في الموضع المضاعَف: 22 ↔ 55 و33 ↔ 66 و44 ↔ 77، لأن 2·2 = 4 و2·5 = 10 → 1 ينتهيان بإسهام قيم تختلف بمضاعف للعشرة عند ضم الخانة المجاورة. وهذه أندر عمليًا من زلّات الخانة الواحدة، ولهذا اعتُبرت تغطية لون كافية لمشغّلي التثقيب في الخمسينيات — انظر تاريخًا موجزًا للون.

مخططات أقوى

  • خوارزمية Verhoeff (1969) تستخدم الزمرة الزوجية D5 وتكشف كل أخطاء الخانة الواحدة وكل التبديلات المتجاورة.
  • خوارزمية Damm (2004) تحقق الشيء نفسه بجدول شبه زمرة أبسط ودون حالات خاصة.
  • يعرّف ISO 7064 عدة متغيرات mod-11 وmod-97 تُستخدم في IBAN وISBN.
لم تنتقل شبكات الدفع أبدًا لأن القاعدة المثبّتة ضخمة، ولون كافية لغرضها الضيق، والأمن الحقيقي يسكن في التفويض — لا في خانة التحقق.

أسئلة شائعة

أي خطأ تفشل لون في اكتشافه؟

تبديل 0 و9 المتجاورتين (09 ↔ 90)، وبعض الاستبدالات التوأمية مثل 22 ↔ 55 في الموضع المضاعَف.

هل توجد خانة تحقق أفضل من لون؟

نعم — Verhoeff وDamm تكشفان كل أخطاء الخانة الواحدة وكل التبديلات المتجاورة، لكن شبكات البطاقات تُبقي لون للتوافق.

Educational content — not legal or financial advice. Open the interactive Check Digit Lab →