Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working random IBAN generation for France #46

Open
nvuillam opened this issue Feb 23, 2018 · 2 comments
Open

Working random IBAN generation for France #46

nvuillam opened this issue Feb 23, 2018 · 2 comments

Comments

@nvuillam
Copy link

nvuillam commented Feb 23, 2018

For French IBANs, there can be different consistency checks

  • Existing BankCode
  • Existing BrancheCode
  • Consistency of FR nationalCheckDigit

So random generated IBANs with Country.FR are not valid.

Here is a workaround for anyone looking for it ( maybe you can integrate it in your library if you like )

      String bankCode = "30006" ;
      String branchCode = "00001" ;
      Random r = new Random();
      int Low = 10;
      int High = 1000000;
      int AccountNumberInt = r.nextInt(High-Low) + Low;
      String AccountNumberStr = String.valueOf(AccountNumberInt);
      String AccountNumber = StringUtils.repeat("0", 11 - AccountNumberStr.length()) + AccountNumberStr;
      long a100000000000 =  (long) 100000000000.0;
      Long nationalCheckDigitInt = 97 - (((Long.valueOf(bankCode) % 97 * 100000 + Integer.valueOf(branchCode)) % 97 * a100000000000 + Integer.valueOf(AccountNumber)) % 97) * 100 % 97;
       String nationalCheckDigit = String.valueOf(nationalCheckDigitInt) ;
       Iban iban = new Iban.Builder().countryCode(CountryCode.FR).bankCode(bankCode).branchCode(branchCode).accountNumber(AccountNumber).nationalCheckDigit(nationalCheckDigit).buildRandom();  
@thecoder8890
Copy link

This is more effective

String bankCode = "30006" ; String branchCode = "00001" ; Random r = new Random(); int Low = 10; int High = 1000000; int AccountNumberInt = r.nextInt(High-Low) + Low; String AccountNumberStr = String.valueOf(AccountNumberInt); String AccountNumber = StringUtils.repeat("0", 11 - AccountNumberStr.length()) + AccountNumberStr; long a100000000000 = (long) 100000000000.0; Long nationalCheckDigitInt = 97 - (((Long.valueOf(bankCode) % 97 * 100000 + Integer.valueOf(branchCode)) % 97 * a100000000000 + Long.valueOf(AccountNumber)) % 97) * 100 % 97; String nationalCheckDigit = String.valueOf(nationalCheckDigitInt) ; Iban iban = new Iban.Builder().countryCode(CountryCode.FR).bankCode(bankCode).branchCode(branchCode).accountNumber(AccountNumber).nationalCheckDigit(nationalCheckDigit).buildRandom();

@bllakinci
Copy link

The basic formula to calculate nationalCheckDigit for FR is like this;

  @param bankCode 5 character
  @param branchCode 5 character
  @param accountNumber 11 character

  cleRibKey = - (bankCode * pow(10,18)  + branchCode * pow(10,13) + accountNumber * pow(10,2))  % 97
  cleRibKey = - (bankCode * 89          + branchCode * 15         + accountNumber * 3)          % 97

If you want to create an account number that contains letters you need to replace characters in the account number with the below numbers. After that, you can calculate the cleRibKey with the above formula.

A, J = 1
B, K, S = 2
C, L, T = 3
D, M, U = 4
E, N, V = 5
F, O, W = 6
G, P, X = 7
H, Q, Y = 8
I, R, Z = 9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants