Skip to content

Instantly share code, notes, and snippets.

Created January 16, 2014 03:01
Show Gist options
  • Save anonymous/8449136 to your computer and use it in GitHub Desktop.
Save anonymous/8449136 to your computer and use it in GitHub Desktop.
Helps german, austrian and swiss to calculate IBANs from their old account data. On a side-note, you don't need a BIC inside your country, IBAN is enough.
package io.sepa.hbci
/**
* Helps german, austrian and swiss to calculate IBANs from their old account data.
* On a side-note, you don't need a BIC inside your country, IBAN is enough.
*/
object IBAN {
/**
* @param country 2-letter ISO country code
* @param kto Kontonummer / Accountnumber
* @param blz Bankleitzahl / Bankroutingnumber
* @return International Bank Account Number (IBAN)
*/
def apply(country: String, kto: String, blz: String): Option[String] = {
if (country.length != 2) return None
val countrycode = "%02d%02d".format(country.toUpperCase.charAt(0).toInt - 55, country.toUpperCase.charAt(1).toInt - 55)
val checksum = "%02d".format(98 - (BigInt("%08d%010d%s00".format(blz.toInt, kto.toInt, countrycode)) % 97))
Some("%s%s%08d%010d".format(country, checksum, blz.toInt, kto.toInt))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment