<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2Ftrappist_the_monk%2Fcheck_digit</id>
	<title>Module:Sandbox/trappist the monk/check digit - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2Ftrappist_the_monk%2Fcheck_digit"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/check_digit&amp;action=history"/>
	<updated>2026-07-30T22:37:43Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/check_digit&amp;diff=146607&amp;oldid=prev</id>
		<title>imported&gt;Legoktm: Replace Module:No globals with require( &quot;strict&quot; )</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/check_digit&amp;diff=146607&amp;oldid=prev"/>
		<updated>2022-10-23T21:02:37Z</updated>

		<summary type="html">&lt;p&gt;Replace &lt;a href=&quot;/research/Module:No_globals&quot; title=&quot;Module:No globals&quot;&gt;Module:No globals&lt;/a&gt; with require( &amp;quot;strict&amp;quot; )&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require(&amp;#039;strict&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
local function err_msg_make (msg)&lt;br /&gt;
	return &amp;#039;&amp;lt;span class=&amp;quot;error&amp;quot; style=&amp;quot;font-size:100%&amp;quot;&amp;gt;error: &amp;#039; .. msg .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function is_valid_isxn_13 (isxn_str)&lt;br /&gt;
	local temp=0;&lt;br /&gt;
	&lt;br /&gt;
	isxn_str = { isxn_str:byte(1, 13) };										-- make a table of byte values &amp;#039;0&amp;#039; → 0x30 .. &amp;#039;9&amp;#039; → 0x39&lt;br /&gt;
	for i, v in ipairs( isxn_str ) do&lt;br /&gt;
		temp = temp + (3 - 2*(i % 2)) * tonumber( string.char(v) );				-- multiply odd index digits by 1, even index digits by 3 and sum; includes check digit&lt;br /&gt;
	end&lt;br /&gt;
	return temp % 10 == 0;														-- sum modulo 10 is zero when isbn-13/ismn is correct&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function check_digit_calc (id_str)&lt;br /&gt;
	local temp=0;&lt;br /&gt;
	&lt;br /&gt;
	id_str = { id_str:byte(1, 12) };											-- make a table of byte values &amp;#039;0&amp;#039; → 0x30 .. &amp;#039;9&amp;#039; → 0x39&lt;br /&gt;
	for i, v in ipairs( id_str ) do&lt;br /&gt;
		temp = temp + (3 - 2*(i % 2)) * tonumber( string.char(v) );				-- multiply odd index digits by 1, even index digits by 3 and sum; includes check digit&lt;br /&gt;
	end&lt;br /&gt;
	temp = 10 - (temp % 10);													-- subtract sum modulo 10 from 10 to get the check digit&lt;br /&gt;
	return (10 == temp) and 0 or temp;											-- if the result is 10, return 0; return result else&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function main (frame)&lt;br /&gt;
	local id = frame.args[1];													-- get the id string&lt;br /&gt;
	local id_str = id;															-- copy that we will modify to do check digit calculations&lt;br /&gt;
	local check_digit;&lt;br /&gt;
	&lt;br /&gt;
	if id_str:match (&amp;#039;%D&amp;#039;) then													-- look for characters that are not digits&lt;br /&gt;
		return err_msg_make (&amp;#039;id has non-digit characters: &amp;#039; .. id_str);&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if &amp;#039;&amp;#039; == id_str then														-- make sure id is not the empty string&lt;br /&gt;
		return err_msg_make (&amp;#039;id is empty&amp;#039;);&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if 12 &amp;lt; id_str:len() then													-- make sure that the id is no longer than 12 digits&lt;br /&gt;
		return err_msg_make (&amp;#039;id has too many characters (&amp;#039; .. id_str:len() .. &amp;#039;): &amp;#039; .. id_str);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if 0 == tonumber(id_str) then												-- make sure that the id is not 0&lt;br /&gt;
		return err_msg_make (&amp;#039;id may not be zero&amp;#039;);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	id_str = string.rep (&amp;#039;0&amp;#039;, 12-id:len()) .. id;								-- left fill with 0s to a string length of 12&lt;br /&gt;
	check_digit = check_digit_calc (id_str);									-- calculate the check digit&lt;br /&gt;
	if is_valid_isxn_13 (id_str .. check_digit) then							-- append check digit to 12-digit id and validate&lt;br /&gt;
		return id .. &amp;#039;.&amp;#039; .. check_digit;										-- return original id with dot-separated check digit&lt;br /&gt;
	else&lt;br /&gt;
		return err_msg_make (&amp;#039;calculation failure: &amp;#039; .. check_digit)							-- did not validate&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {main = main}&lt;/div&gt;</summary>
		<author><name>imported&gt;Legoktm</name></author>
	</entry>
</feed>