fhoeben / hsac-fitnesse-plugin

Plugin to add some additional features to a FitNesse wiki.
Apache License 2.0
20 stars 10 forks source link

Random #11

Closed keetron closed 7 years ago

keetron commented 7 years ago

When going over the !random function, I was thinking about !randomIBAN. We could use this list for Dutch banks to get valid SEPA numbers: https://www.betaalvereniging.nl/giraal-en-online-betalen/sepa-documentatie-voor-nederland/bic-afleiden-uit-iban/

I don't doubt there is something similar for all european banks (although I have some trouble finding a proper list for SEPA connected banks. (small update: that is because SEPA is a mess: https://bank.codes/iban/examples/ )

Urgency is low, but I can think of a few uses already.

fhoeben commented 7 years ago

Maybe https://www.generateiban.com/test-iban/ could be used, which already generates a random

keetron commented 7 years ago

Sometimes the simple solutions are best. The SLIM scenario implementation with the hsac plugin would be something like?

|scenario|generate iban| |open|https://www.generateiban.com/test-iban/| |set|.//*[@id='iban']|for|@iban|

On Sun, Nov 20, 2016 at 12:32 PM, Fried Hoeben notifications@github.com wrote:

Maybe https://www.generateiban.com/test-iban/ could be used, which already generates a random

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fhoeben/hsac-fitnesse-plugin/issues/11#issuecomment-261772734, or mute the thread https://github.com/notifications/unsubscribe-auth/AIdjhwN8-U0fMR7mXKUTt9zQqhXnRVw9ks5rAC_ggaJpZM4K3gob .

fhoeben commented 7 years ago

I believe that approach would be more like:

|scenario|generate iban|
|open|https://www.generateiban.com/test-iban/|
|$iban=|value of|id=iban|
fhoeben commented 7 years ago

But a lot faster would be an approach using Java (of course instead of opening in browser). https://github.com/arturmkrtchyan/iban4j Seems to be a library that also supports generating a random iban for a country: Iban iban = Iban.random(CountryCode.NL);

But I have no idea whether it supports the '11-proef' for Dutch bban numbers, or has actual bank codes for the Netherlands

fhoeben commented 7 years ago

On https://cyberwar.nl/elfproef.html I found a pure Javascript generator for Dutch IBANs. This can probably be used as a basis to create a Java implementation that does the same...

// coded by mrkoot@2011-04-12 
// IBAN added mrkoot@2014-08-18
// IBAN bugfix mrkoot@2015-06-11 kudos to oiseaubelle

function elfProefBank(rekening) {
  p1 = rekening.substr(0, 1) * 9;
  p2 = rekening.substr(1, 1) * 8;
  p3 = rekening.substr(2, 1) * 7;
  p4 = rekening.substr(3, 1) * 6;
  p5 = rekening.substr(4, 1) * 5;
  p6 = rekening.substr(5, 1) * 4;
  p7 = rekening.substr(6, 1) * 3;
  p8 = rekening.substr(7, 1) * 2;
  p9 = rekening.substr(8, 1) * 1;
  totaal = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9;
  remainder = totaal % 11;
  return (remainder == 0);
}

function elfProefBSN(bsn) {
  p1 = bsn.substr(0, 1) * 9;
  p2 = bsn.substr(1, 1) * 8;
  p3 = bsn.substr(2, 1) * 7;
  p4 = bsn.substr(3, 1) * 6;
  p5 = bsn.substr(4, 1) * 5;
  p6 = bsn.substr(5, 1) * 4;
  p7 = bsn.substr(6, 1) * 3;
  p8 = bsn.substr(7, 1) * 2;
  p9 = bsn.substr(8, 1) * -1;
  totaal = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9;
  remainder = totaal % 11;
  return (remainder == 0);
}

function generateBSN(aantal) {
  for (var i=0;i<aantal;i++) {
    var success=false;
    while (!success) { var s="";
      for (var j=0;j<9;j++) {
        var y = Math.floor(Math.random()*10);
        s = s + y.toString();
      }

      if (elfProefBSN(s)==true) {
        success = true;
        document.generator.outputtxtBSN.value += s +'\n';
      }
    }
  }
}

// IBAN-meuk:

land="NL";
bics=[
"ABNA",//   ABN AMRO BANK
"FTSB",//   ABN AMRO BANK (ex FORTIS BANK)
"AEGO",//   AEGON BANK
"ANAA",//   ALLIANZ NEDERLAND ASSET MANAGEMENT
"ANDL",//   ANADOLUBANK
"ARBN",//   ACHMEA BANK
"ARSN",//   ARGENTA SPAARBANK
"ARTE",//   GE ARTESIA BANK
"ASNB",//   ASN BANK
"ASRB",//   ASR BANK
"ATBA",//   AMSTERDAM TRADE BANK
"BBRU",//   ING BELGIE, BREDA
"BCDM",//   BANQUE CHAABI DU MAROC
"BCIT",//   INTESA SANPAOLO
"BICK",//   BINCKBANK
"BKCH",//   BANK OF CHINA
"BKMG",//   BANK MENDES GANS
"BLGW",//   BLG WONEN
"BMEU",//   BMCE EUROSERVICES
"BNGH",//   BANK NEDERLANDSE GEMEENTEN
"BNPA",//   BNP PARIBAS
"BOFA",//   BANK OF AMERICA
"BOFS",//   BANK OF SCOTLAND, AMSTERDAM
"BOTK",//   BANK OF TOKYO-MITSUBISHI UFJ
"CHAS",//   JPMORGAN CHASE
"CITC",//   CITCO BANK
"CITI",//   CITIBANK INTERNATIONAL
"COBA",//   COMMERZBANK
"DEUT",//   DEUTSCHE BANK (bij alle SEPA transacties)
"DHBN",//   DEMIR-HALK BANK
"DLBK",//   DELTA LLOYD BANK
"DNIB",//   NIBC BANK
"FBHL",//   CREDIT EUROPE BANK
"FLOR",//   DE NEDERLANDSCHE BANK
"FRBK",//   FRIESLAND BANK
"FRGH",//   FGH BANK
"FVLB",//   F. VAN LANSCHOT BANKIERS
"GILL",//   THEODOOR GILISSEN
"HAND",//   SVENSKA HANDELSBANKEN
"HHBA",//   HOF HOORNEMAN BANKIERS
"HSBC",//   HSBC BANK
"ICBK",//   INDUSTRIAL & COMMERCIAL BANK OF CHINA
"INGB",//   ING BANK
"INSI",//   INSINGER DE BEAUFORT
"ISBK",//   ISBANK
"KABA",//   YAPI KREDI BANK
"KASA",//   KAS BANK
"KNAB",//   KNAB
"KOEX",//   KOREA EXCHANGE BANK
"KRED",//   KBC BANK
"LOCY",//   LOMBARD ODIER DARIER HENTSCH & CIE
"LOYD",//   LLOYDS TSB BANK
"LPLN",//   LEASEPLAN CORPORATION
"MHCB",//   MIZUHO CORPORATE BANK
"NNBA",//   NATIONALE-NEDERLANDEN BANK
"NWAB",//   NEDERLANDSE WATERSCHAPSBANK
"OVBN",//   LEVOB BANK
"RABO",//   RABOBANK
"RBOS",//   ROYAL BANK OF SCOTLAND
"RBRB",//   REGIOBANK
"SNSB",//   SNS BANK
"SOGE",//   SOCIETE GENERALE
"STAL",//   STAALBANKIERS
"TEBU",//   THE ECONOMY BANK
"TRIO",//   TRIODOS BANK
"UBSW",//   UBS BANK
"UGBI",//   GARANTIBANK INTERNATIONAL
"VOWA",//   VOLKSWAGEN BANK
"ZWLB" //   ZWITSERLEVENBANK
];

function generateIBAN(aantal) {
  for (var i=0;i<aantal;i++) {
    var success=false;
    while (!success) { var s="";
      for (var j=0;j<9;j++) {
        var y = Math.floor(Math.random()*10);
        s = s + y.toString();
      }

      if (elfProefBank(s)==true) {
        iban = geefIBAN(s);
        //--- ranzige, ranzige hack om "NaNundefined" uit de uitvoer te filteren
        if (iban.indexOf("NaNundefined")==-1){
          success = true;
          document.generator.outputtxtIBAN.value += iban +'\n';
        }
        //----
      }
    }
  }
}

function geefIBAN(reknr){
bank = bics[Math.round(Math.random()*bics.length-1)];
tmp="";

while (reknr.length < 10) reknr = "0" + reknr;

tmp=bank+reknr+land;
tmp2="";

for (var j=0; j < tmp.length; j++) {
  if (/^[A-Z]+$/.test(tmp[j]))
    tmp2 += (tmp.charCodeAt(j)-55);
  else
    tmp2 += tmp[j];
}
tmp2 += "00";

// nu moet tmp2 % 97 worden gedaan, maar tmp2 bevat een getal dat in de 
// meeste (?) browsers groter is dan [Number.MAX_VALUE]. Vandaar deze
// hulpfunctie ipv 'tmp2 % 97' als JavaScript-code uitvoeren.
// functie is geleend van http://www.webdeveloper.com/forum/showthread.php?282331-modulo-on-big-numbers
function modulo( aNumStr, aDiv) {
  var tmp = "";
  var i, r;
  for ( i=0; i<aNumStr.length ; i++) {
    tmp += aNumStr.charAt(i);
    r = tmp % aDiv;
    tmp = r.toString( 10);
    }
  return tmp / 1;
}

controle = (98 - modulo(tmp2, 97)).toString();
if(controle.length < 2)
  controle = "0" + controle;
iban = land + controle + bank + reknr;
return iban;
}
keetron commented 7 years ago

Which is close to what I was planning on building if nothing new would come up after I finish my work on Monday or Tuesday... ;-)

Op 20 nov. 2016 5:03 p.m. schreef "Fried Hoeben" notifications@github.com:

On https://cyberwar.nl/elfproef.html I found a pure Javascript generator for Dutch IBANs. This can probably be used as a basis to create a Java implementation that does the same...

// coded by mrkoot@2011-04-12 // IBAN added mrkoot@2014-08-18 // IBAN bugfix mrkoot@2015-06-11 kudos to oiseaubelle

function elfProefBank(rekening) { p1 = rekening.substr(0, 1) * 9; p2 = rekening.substr(1, 1) * 8; p3 = rekening.substr(2, 1) * 7; p4 = rekening.substr(3, 1) * 6; p5 = rekening.substr(4, 1) * 5; p6 = rekening.substr(5, 1) * 4; p7 = rekening.substr(6, 1) * 3; p8 = rekening.substr(7, 1) * 2; p9 = rekening.substr(8, 1) * 1; totaal = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9; remainder = totaal % 11; return (remainder == 0); }

function elfProefBSN(bsn) { p1 = bsn.substr(0, 1) * 9; p2 = bsn.substr(1, 1) * 8; p3 = bsn.substr(2, 1) * 7; p4 = bsn.substr(3, 1) * 6; p5 = bsn.substr(4, 1) * 5; p6 = bsn.substr(5, 1) * 4; p7 = bsn.substr(6, 1) * 3; p8 = bsn.substr(7, 1) * 2; p9 = bsn.substr(8, 1) * -1; totaal = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9; remainder = totaal % 11; return (remainder == 0); }

function generateBSN(aantal) { for (var i=0;i<aantal;i++) { var success=false; while (!success) { var s=""; for (var j=0;j<9;j++) { var y = Math.floor(Math.random()*10); s = s + y.toString(); }

  if (elfProefBSN(s)==true) {
    success = true;
    document.generator.outputtxtBSN.value += s +'\n';
  }
}

} }

// IBAN-meuk:

land="NL"; bics=[ "ABNA",// ABN AMRO BANK "FTSB",// ABN AMRO BANK (ex FORTIS BANK) "AEGO",// AEGON BANK "ANAA",// ALLIANZ NEDERLAND ASSET MANAGEMENT "ANDL",// ANADOLUBANK "ARBN",// ACHMEA BANK "ARSN",// ARGENTA SPAARBANK "ARTE",// GE ARTESIA BANK "ASNB",// ASN BANK "ASRB",// ASR BANK "ATBA",// AMSTERDAM TRADE BANK "BBRU",// ING BELGIE, BREDA "BCDM",// BANQUE CHAABI DU MAROC "BCIT",// INTESA SANPAOLO "BICK",// BINCKBANK "BKCH",// BANK OF CHINA "BKMG",// BANK MENDES GANS "BLGW",// BLG WONEN "BMEU",// BMCE EUROSERVICES "BNGH",// BANK NEDERLANDSE GEMEENTEN "BNPA",// BNP PARIBAS "BOFA",// BANK OF AMERICA "BOFS",// BANK OF SCOTLAND, AMSTERDAM "BOTK",// BANK OF TOKYO-MITSUBISHI UFJ "CHAS",// JPMORGAN CHASE "CITC",// CITCO BANK "CITI",// CITIBANK INTERNATIONAL "COBA",// COMMERZBANK "DEUT",// DEUTSCHE BANK (bij alle SEPA transacties) "DHBN",// DEMIR-HALK BANK "DLBK",// DELTA LLOYD BANK "DNIB",// NIBC BANK "FBHL",// CREDIT EUROPE BANK "FLOR",// DE NEDERLANDSCHE BANK "FRBK",// FRIESLAND BANK "FRGH",// FGH BANK "FVLB",// F. VAN LANSCHOT BANKIERS "GILL",// THEODOOR GILISSEN "HAND",// SVENSKA HANDELSBANKEN "HHBA",// HOF HOORNEMAN BANKIERS "HSBC",// HSBC BANK "ICBK",// INDUSTRIAL & COMMERCIAL BANK OF CHINA "INGB",// ING BANK "INSI",// INSINGER DE BEAUFORT "ISBK",// ISBANK "KABA",// YAPI KREDI BANK "KASA",// KAS BANK "KNAB",// KNAB "KOEX",// KOREA EXCHANGE BANK "KRED",// KBC BANK "LOCY",// LOMBARD ODIER DARIER HENTSCH & CIE "LOYD",// LLOYDS TSB BANK "LPLN",// LEASEPLAN CORPORATION "MHCB",// MIZUHO CORPORATE BANK "NNBA",// NATIONALE-NEDERLANDEN BANK "NWAB",// NEDERLANDSE WATERSCHAPSBANK "OVBN",// LEVOB BANK "RABO",// RABOBANK "RBOS",// ROYAL BANK OF SCOTLAND "RBRB",// REGIOBANK "SNSB",// SNS BANK "SOGE",// SOCIETE GENERALE "STAL",// STAALBANKIERS "TEBU",// THE ECONOMY BANK "TRIO",// TRIODOS BANK "UBSW",// UBS BANK "UGBI",// GARANTIBANK INTERNATIONAL "VOWA",// VOLKSWAGEN BANK "ZWLB" // ZWITSERLEVENBANK ];

function generateIBAN(aantal) { for (var i=0;i<aantal;i++) { var success=false; while (!success) { var s=""; for (var j=0;j<9;j++) { var y = Math.floor(Math.random()*10); s = s + y.toString(); }

  if (elfProefBank(s)==true) {
    iban = geefIBAN(s);
    //--- ranzige, ranzige hack om "NaNundefined" uit de uitvoer te filteren
    if (iban.indexOf("NaNundefined")==-1){
      success = true;
      document.generator.outputtxtIBAN.value += iban +'\n';
    }
    //----
  }
}

} }

function geefIBAN(reknr){ bank = bics[Math.round(Math.random()*bics.length-1)]; tmp="";

while (reknr.length < 10) reknr = "0" + reknr;

tmp=bank+reknr+land; tmp2="";

for (var j=0; j < tmp.length; j++) { if (/^[A-Z]+$/.test(tmp[j])) tmp2 += (tmp.charCodeAt(j)-55); else tmp2 += tmp[j]; } tmp2 += "00";

// nu moet tmp2 % 97 worden gedaan, maar tmp2 bevat een getal dat in de // meeste (?) browsers groter is dan [Number.MAX_VALUE]. Vandaar deze // hulpfunctie ipv 'tmp2 % 97' als JavaScript-code uitvoeren. // functie is geleend van http://www.webdeveloper.com/forum/showthread.php?282331-modulo-on-big-numbers function modulo( aNumStr, aDiv) { var tmp = ""; var i, r; for ( i=0; i<aNumStr.length ; i++) { tmp += aNumStr.charAt(i); r = tmp % aDiv; tmp = r.toString( 10); } return tmp / 1; }

controle = (98 - modulo(tmp2, 97)).toString(); if(controle.length < 2) controle = "0" + controle; iban = land + controle + bank + reknr; return iban; }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fhoeben/hsac-fitnesse-plugin/issues/11#issuecomment-261786769, or mute the thread https://github.com/notifications/unsubscribe-auth/AIdjhyO_vbf4kC212dADzjDXj0DCZy3Mks5rAG9ngaJpZM4K3gob .

keetron commented 7 years ago

With some additional reconsideration, one would like the randomIBAN to be able to:

It needs to be some java anyway so it can be run locally, to avoid having to go to the outside world. It is a nice puzzle to solve anyway, I can use the practice...

fhoeben commented 7 years ago

If it is limited to Dutch IBANs I recommend you call it something like randomIBAN_NL, or you could (of course) make the country one of the arguments.

keetron commented 7 years ago

Look what I found: https://github.com/arturmkrtchyan/iban4j

Basically, I will make this into a wikiword that will take country (optional) and bank (optional) as inputs.

keetron commented 7 years ago

On the other hand, it might be a bit to big for the problem I am trying to solve. Not sure about this one. Anyone else reading this in dire need of a random IBAN generator?

fhoeben commented 7 years ago

@keetron What do you think of #20? Does that meet your needs?

keetron commented 7 years ago

It meets my needs almost perfectly. I do see a few possible improvements when going over the code. There is some overlap (random element from list) with the RandomEmail PR !RandomIban without parameters gives a Dutch Iban by default. I would prefer a random Iban, even tho it would be a Dutch one now as there is only one implementation. Make it robust for future IbanAdditions and have this reflected in the entire PR.

@tcnh I can make the changes I mean later this week, would that work for you? Basically I would make a generic input processor that calls a country-specific class that contains the generator code and the Enum for the banks.

tcnh commented 7 years ago

Nice, I never saw this Issue, I see we did however find the same resources to lend stuff from :)

Suggested improvements would be great. For now, I needed dutch IBAN's for my testing. I had a look at foreign IBAN's (hence the parameterization already being done, but the issue I faced is that generating a valid BBAN for each country wil ask for country-specific implementations. Maybe just add them as we need them (I expect to get a request for german and belgian IBAN's in my current project rather soon..)

keetron commented 7 years ago

Best would be to refactor for real random Iban right from the start else you will write your tests using !RandomIban expecting a Dutch Iban, making backwards compatibility a pain when changing the no parameter version to generate using the available country list.

keetron commented 7 years ago

resolved with PR #20 and #21