Skip to content

Instantly share code, notes, and snippets.

@NewEraCracker
Last active February 20, 2018 11:37
Show Gist options
  • Save NewEraCracker/fd34a464544c1acb0e250ee85ce6f01f to your computer and use it in GitHub Desktop.
Save NewEraCracker/fd34a464544c1acb0e250ee85ce6f01f to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<script><!--
function checksum(str, eight = false)
{
regex = new RegExp('^([A-Z]{1})([A-F]{1})?([0-9]{9,10}[1-9])$');
matches = regex.exec(str);
if ( (typeof matches == undefined) || (!matches) ) {
return false;
}
num = 0;
str = matches[3];
if ( (typeof matches[2] != undefined) && (matches[2]) ) {
str += "" + matches[2].charCodeAt(0) - 'A'.charCodeAt(0) + 2;
}
do {
num = 0;
for(i = 0; i < str.length; i++) {
num += str.charCodeAt(i) - '0'.charCodeAt(0);
}
str = "" + num;
} while (num > 9);
if (eight) {
str += "" + (matches[1].charCodeAt(0) - 'A'.charCodeAt(0) + 1);
do {
num = 0;
for(i = 0; i < str.length; i++) {
num += str.charCodeAt(i) - '0'.charCodeAt(0);
}
str = "" + num;
} while (num > 9);
}
return num;
}
function check()
{
ccode = parseInt(window.document.checknote.countrycode.value);
cletr = String.fromCharCode((ccode + 'A'.charCodeAt(0) - 1));
//------------------------
// 8-check
quer = checksum(("" + cletr + window.document.checknote.num.value), true);
window.document.checknote.checksum.value = quer;
if ( quer==8 ) {
window.document.checknote.valid.value = "passed, valid";
} else {
window.document.checknote.valid.value = "checksum MISMATCH, invalid";
}
//------------------------
// Identity-check
quer = checksum(("" + cletr + window.document.checknote.num.value), false);
window.document.checknote.idchecksum.value = quer;
quer = quer + ccode;
if ( (quer==8) || (quer==17) || (quer==26) || (quer==35) ) {
window.document.checknote.idvalid.value = "passed, valid";
} else {
window.document.checknote.idvalid.value = "identity MISMATCH, invalid";
}
}
//--></script>
<title>Euro Note Serial Number Check</title>
<meta name="viewport" content="width=device-width"/>
</head>
<body style="text-align:center">
<form name="checknote">
<select name="countrycode">
<option value="2">B = Lithuania (not yet)</option>
<option value="3">C = Latvia (not yet)</option>
<option value="4">D = Poland</option>
<option value="5">E = Slovakia</option>
<option value="6">F = Malta</option>
<option value="7">G = Cypris</option>
<option value="8">H = Slovenia</option>
<option value="10">J = United Kingdom (not yet)</option>
<option value="11">K = Sweden (not yet)</option>
<option value="12">L = Finnland</option>
<option value="13">M = Portugal</option>
<option value="14">N = Austria</option>
<option value="16">P = Netherlands</option>
<option value="18">R = Luxembourg (no own printing yet)</option>
<option value="19">S = Italy</option>
<option value="20">T = Ireland</option>
<option value="21">U = France</option>
<option value="22">V = Spain</option>
<option value="23">W = Germany (Leipzig)</option>
<option value="24" selected>X = Germany (Munich)</option>
<option value="25">Y = Greece</option>
<option value="26">Z = Belgium</option>
</select>
<input name="num" type="text" size="14" maxlength="11">
<input type="button" value="Check" onClick="check();">
<p>8-Check<br/>
Checksum: <input name="checksum" type="text" size="1">
<input name="valid" type="text" size="30"></p>
<p>Identity-Check<br/>
Checksum: <input name="idchecksum" type="text" size="1">
<input name="idvalid" type="text" size="30"></p>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment