How to resolve the algorithm IBAN step by step in the UNIX Shell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm IBAN step by step in the UNIX Shell programming language

Table of Contents

Problem Statement

The   International Bank Account Number (IBAN)   is an internationally agreed means of identifying bank accounts across national borders with a reduced risk of propagating transcription errors. The IBAN consists of up to 34 alphanumeric characters:

The check digits enable a sanity check of the bank account number to confirm its integrity even before submitting a transaction.

Validate the following fictitious IBAN:   GB82 WEST 1234 5698 7654 32

Details of the algorithm can be found on the Wikipedia page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm IBAN step by step in the UNIX Shell programming language

Source code in the unix programming language

declare -A base36=(
    [A]=10 [B]=11 [C]=12 [D]=13 [E]=14 [F]=15 [G]=16 [H]=17 [I]=18
    [J]=19 [K]=20 [L]=21 [M]=22 [N]=23 [O]=24 [P]=25 [Q]=26 [R]=27
    [S]=28 [T]=29 [U]=30 [V]=31 [W]=32 [X]=33 [Y]=34 [Z]=35
)

function is_iban {
    local -u acct=${1//[^[:alnum:]]/}
    acct=${acct:4}${acct:0:4}
    local i char digits=""
    for ((i=0; i<${#acct}; i++)); do
        char=${acct:i:1}
        digits+=${base36[$char]:-$char}
    done
    local mod=$(mod97 $digits)
    (( mod == 1 ))
}

function mod97 {
    local D=$1
    N=${D:0:9}
    D=${D:9}
    while [[ -n $D ]]; do
        mod=$(( N % 97 ))
        N=$(printf "%02d%s" $mod ${D:0:7})
        D=${D:7}
    done
    echo $(( N % 97 ))
}

for test in "GB82 WEST 1234 5698 7654 32" "GB42 WEST 1234 5698 7654 32"; do
    printf "%s : " "$test"
    is_iban "$test" && echo yes || echo no
done


  

You may also check:How to resolve the algorithm Determine if a string is collapsible step by step in the Cowgol programming language
You may also check:How to resolve the algorithm Primorial numbers step by step in the Elixir programming language
You may also check:How to resolve the algorithm Guess the number step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Sudoku step by step in the PHP programming language
You may also check:How to resolve the algorithm Polynomial regression step by step in the Swift programming language