Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Checksum for PPs No in Javascript

Options
  • 16-04-2008 12:50pm
    #1
    Registered Users Posts: 61 ✭✭


    I am looking for a recommended source to help with writing javascript for a checksum of a PPS NO. I am an evening student & my only resourse are class notes, which are limited to say the least. I have to lodge this assignment shortly. I have tried the library & the recommended books have been swallowed up by the day students!!.
    Any help would be appreciated.

    elgan:(


Comments

  • Registered Users Posts: 2,494 ✭✭✭kayos


    Google is your friend!

    http://en.wikipedia.org/wiki/Personal_Public_Service_Number
    Check Character

    The format of the PPS number is seven digits plus a check character. A second character may be used. If so it is always a 'W'.

    The check character is calculated using a weighted addition of all the numbers and modulus calculation. It therefore checks for incorrectly entered digits and for digit transposition (digits in the wrong order will alter the sum due to weightings).

    Calculation

    In reverse order, each digit is multiplied by a weight, 2, 3, and so on until the first digit is multiplied by 8. Add up each result. Divide by 23 and the remainder (modulus 23) will indicate the character position on the alphabet.

    Thus the PPS number 1234567 will be calculated as the sum of 7*2, 6*3, 5*4, 4*5, 3*6, 2*7 and 1*8. This 112 when divided by 23 leaves a remainder of 20. The twentieth letter of the English alphabet is 'T'. The correct PPS number is therefore 1234567T.

    Go code :)


  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    It doesn't really say what you have to do if you get a remainder of 0. http://emhain.wit.ie/~p02csd22/Emhain/final/finalreport.html#achieved doesn't seem accurate. Not only have they used incorrect number in their example, these lads say I is the 10th letter of alphabet, while its the ninth. They include a trailing 0 as part of the number in the calculation even though 0 muliplied by anything is always 0. The trailing number is not part of the final result. Either way, if your following the Wikipedia explanation, here is a simple scrappy C source, you can follow along when implementing a javascript version...
    #include <stdio.h>
    
    void usage(char* exe) {
         printf("Usage: &#37;s <PPS No.>\ne.g. %s 7654321", exe, exe);
    }
    
    int main(int argc, char** argv) {
           unsigned short y, weight, sum, tmp;
           
           if ((argc < 2) || (strlen(argv[1]) != 7)) {
              usage(argv[0]);
    	      exit(1);
           }             
           
           weight = 2; sum = 0;
           
           for ( y = 7 ; y > 0; y--) {
               if ( ((int)argv[1][y-1] < 48) || ((int)argv[1][y-1] > 57) ) {
                  usage(argv[0]); exit(1);
               }              
               sum += ((int)argv[1][y-1]-48) * weight;
               weight++;
           }
           tmp = sum % 23;   
           printf("Input:\t%s\nPPS:\t%s%c\n",argv[1],argv[1],tmp+64);       
    }
    

    C:\>pps.exe 3984033
    Input:  3984033
    PPS:    3984033I
    
    C:\>pps.exe 1234567
    Input:  1234567
    PPS:    1234567T
    


  • Registered Users Posts: 5,376 ✭✭✭DublinDilbert


    Well they are doing a modulo 23 division, so they are not using all the letters for the checksum, they are only using 23....

    I would assume they are not using "o", "i" in case they get mixed up with "0" and "1"... i read the wiki earlier and "w" was used for "wife".... so maybe they just use the remaining 23 letters??

    So you can't calculate the ASCII code of the letter by adding 64 to the remainder:-
    tmp = sum % 23;
    printf("Input:\t%s\nPPS:\t%s%c\n",argv[1],argv[1],tmp+64);


    You'll need to use tmp to index down an array which contains the 23 valid check character values in order....


  • Closed Accounts Posts: 2,267 ✭✭✭h57xiucj2z946q


    dunno, need a more solid document on this.


  • Registered Users Posts: 7,398 ✭✭✭fletch


    It doesn't really say what you have to do if you get a remainder of 0.
    Yeh what do you do in the case of 0? Take for example the PPS Number 2495874. The formula will give an answer of 184, then modulus that by 23 will give 0.

    Edit - just read kayos' comment above and see that it automatically defaults to 'W'.


  • Advertisement
  • Registered Users Posts: 4,928 ✭✭✭dingding


    Any ideas if it is possible to check the validity of a PPS no in excel?, say as an input to excel via a form.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    The calculation to verify it is here:
    http://en.wikipedia.org/wiki/Personal_Public_Service_Number#Calculation

    You could write your own VBScript function in Excel to do a check on the number.


  • Registered Users Posts: 4,928 ✭✭✭dingding


    Well they are doing a modulo 23 division, so they are not using all the letters for the checksum, they are only using 23....

    I would assume they are not using "o", "i" in case they get mixed up with "0" and "1"... i read the wiki earlier and "w" was used for "wife".... so maybe they just use the remaining 23 letters??

    So you can't calculate the ASCII code of the letter by adding 64 to the remainder:-
    tmp = sum % 23;
    printf("Input:\t%s\nPPS:\t%s%c\n",argv[1],argv[1],tmp+64);


    You'll need to use tmp to index down an array which contains the 23 valid check character values in order....

    My number used an o as the check digit, so they must use o as one of the letters.


  • Registered Users Posts: 4,766 ✭✭✭cython


    If you can understand PHP, then the Validate_IE class in PEAR has a pre-written method for this which is available open source. You can also establish how it handles a 0 remainder, etc. from it.


Advertisement