Calculate Automatic Packet Reporting System (APRS) passcodes

This Scilab program calculates the "passcode" ("callpass") needed for some APRS applications.

//////////////////////////////////////////////////////////////////////////////
//
// APRS passcode calculator
//
// Calculate the "passcode" ("callpass") needed for some APRS applications
//
//                  Copyright (C) 2012 Christophe DAVID (ON6ZQ)
//              http://www.on6zq.be/w/index.php/Scilab/APRS-passcode
//
//  This program is free software; you  can redistribute it and/or modify it
//  under the terms of the GNU General Public License version 2 as published
//  by the Free Software Foundation (http://www.gnu.org/licenses/gpl.html).
//
//////////////////////////////////////////////////////////////////////////////
//
//                This program was last tested with Scilab 5.5
//                            http://www.scilab.org
//
//////////////////////////////////////////////////////////////////////////////

// A semicolon at the end of an instruction causes the result not to be displayed.

errclear;         // clear all errors
clear;            // kill variables
clearglobal       // kill global variables
clc;              // clear command window
tohome;           // move the cursor to the upper left corner of the Command Window

// stacksize('max'); // increase the size of this stack to the maximum.
stacksize(1e8);   //stacksize('max') does not appear to work on my system ;-(

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

callsign = "XY3ABC";  // bare callsign, no "-5", no "/P", etc.

passcode = uint16(29666);
callsign = convstr(callsign, "u");
l=length(callsign);
for i = 1:2:l
    a = uint16(ascii(part(callsign, i)));
    passcode = bitxor(passcode, a * 256);
    if i < l then
       b = uint16(ascii(part(callsign, i + 1)));    
       passcode = bitxor(passcode, b);
    end
end
passcode = bitand(passcode, uint16(32767));

printf("\nThe passcode for %s is %d", callsign, passcode);

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////