Created
September 26, 2020 11:37
-
-
Save sbuljat/f0cc30ad650b65c90c2b9849f3185a39 to your computer and use it in GitHub Desktop.
ISO 7064 MOD 11,10 Control character calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Iso7064Util { | |
object Mod_11_10 { | |
def calculateControlChar(input: String): String = { | |
var rest = 10 | |
input.map(_.asDigit).foreach { num => | |
val sum = num + rest | |
val subtotal = if (sum % 10 == 0) 10 else sum % 10 | |
rest = (subtotal * 2) % 11 | |
//println(s"digit=$num\tsum=$sum\tsubtotal=$subtotal\trest=$rest") | |
} | |
val control = if (rest == 1) 0 else 11 - rest | |
control.toString | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment