Skip to content

Instantly share code, notes, and snippets.

@sbuljat
Created September 26, 2020 11:37
Show Gist options
  • Save sbuljat/f0cc30ad650b65c90c2b9849f3185a39 to your computer and use it in GitHub Desktop.
Save sbuljat/f0cc30ad650b65c90c2b9849f3185a39 to your computer and use it in GitHub Desktop.
ISO 7064 MOD 11,10 Control character calculator
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