Código PHP:
function reference_encode($name){
$l =strlen($name);
$c = str_split($name);
$code=0;
$con='';
foreach($c as $a){
if(is_int($a)){
$ch = (int)$a;
}else
$ch = (int)ord($a);
echo $ch.'-';
$code+=$ch;
$con.=$ch;
}
return $l.$code.strlen($con);
}
reference_encode('M.1020-S2');
echo '<br>';
reference_encode('M.1021-R2');
A ver si alguno podría echarme una manita