Skip to content

Instantly share code, notes, and snippets.

@hornc
Last active November 20, 2022 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hornc/e0d0b5070b81edbb4a1edd7915d797a4 to your computer and use it in GitHub Desktop.
Save hornc/e0d0b5070b81edbb4a1edd7915d797a4 to your computer and use it in GitHub Desktop.
Validate and ISNI
"""
[copied from https://github.com/internetarchive/openlibrary/pull/6841#issuecomment-1207507062]
I'm recording this here because there is very little information currently about ISNI check digits online.
ISNI uses a checkdigit {0-9, X} calculation system which is called something like "MOD 11-2" and is
defined in the standard [ISO 7064](https://en.wikipedia.org/wiki/ISO/IEC_7064), but you have to pay to read it....
The same "MOD 11-2" system is used by the
Chinese [Resident Identity Card](https://en.wikipedia.org/wiki/Resident_Identity_Card),
which has its own specs and more publicly available code examples.
"""
def validISNI(isni):
isni = isni.upper().replace('X', 'A')
return sum([int(c, 16) * 2**(15-i) for i, c in enumerate(isni)]) % 11 == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment