Organizational Research By

Surprising Reserch Topic

recursive programming style in java card using -'java,exception,recursion,smartcard,javacard'

recursive programming style in java card  using -'java,exception,recursion,smartcard,javacard'

Although recursive programming style isn't recommanded in Java Card, I want to make a little test on the Fibonacci algorithm. I wrote a function that compute the Fibonacci's suite for big integers (represented by byte arrays).

My code is the following:

public static byte[] fibonacci(byte[] n) {
    if (isLEThan1(n)) {
        return n;
    else {
        return add(fibonacci(subtract(n, new byte[]{0x01})),fibonacci(subtract(n,new byte[]{0x02})));

where boolean isLEThan(byte[]) returns true if the integer represented by the byte array is less or equal than 1, false if not.

byte[] add(byte[], byte[]) and byte[] subtract(byte[], byte[]) implement addition and subtraction for big integers represented by byte arrays. They return a new byte array containing the result of the operation.

I thought that by giving a large array to the function described above, I will get an exception such as SystemException.NO_RESURCE because of the number of array instancied by subtract due to recursive calls.

But I have to think that I don't catch the right exception because I get 6F00 as status word.

Here's the list of exceptions that I consider:

try {
    } catch (ArithmeticException e) {
        ISOException.throwIt((short) 0x0100);
    } catch (ArrayStoreException e) {
        ISOException.throwIt((short) 0x0200);
    } catch (APDUException e) {
        ISOException.throwIt(Util.makeShort((byte) 0x03,
            (byte) e.getReason()));
    } catch (CryptoException e) {
        ISOException.throwIt(Util.makeShort((byte) 0x04,
            (byte) e.getReason()));
    } catch (ISOException e) {
        ISOException.throwIt(Util.makeShort((byte) 0x05,
            (byte) e.getReason()));
    } catch (PINException e) {
        ISOException.throwIt(Util.makeShort((byte) 0x06,
            (byte) e.getReason()));
    } catch (ServiceException e) {
        ISOException.throwIt(Util.makeShort((byte) 0x07,
            (byte) e.getReason()));
    } catch (SystemException e) {
        ISOException.throwIt(Util.makeShort((byte) 0x08,
            (byte) e.getReason()));
    } catch (TransactionException e) {
        ISOException.throwIt(Util.makeShort((byte) 0x09,
            (byte) e.getReason()));
    } catch (ClassCastException e) {
        ISOException.throwIt((short) 0x0A00);
    } catch (IndexOutOfBoundsException e) {
        ISOException.throwIt((short) 0x0B00);
    } catch (NegativeArraySizeException e) {
        ISOException.throwIt((short) 0x0C00);
    } catch (NullPointerException e) {
        ISOException.throwIt((short) 0x0D00);
    } catch (SecurityException e) {
        ISOException.throwIt((short) 0x0E00);

So, does somebody have an idea about the exception concerned in that case?

asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.