На даный момент наиболие подходящий вариант, что пришел в голову:
var mas1 = [
[1, 2, 3, 6, 0, 8, 5, 4, 7, 9],
[2, 1, 8, 6, 5, 9, 7, 0, 4, 3],
[7, 6, 1, 5, 8, 4, 2, 9, 3, 0],
[2, 6, 5, 7, 4, 0, 8, 1, 3, 9],
[0, 8, 6, 2, 7, 9, 4, 5, 3, 1],
[5, 7, 8, 0, 6, 9, 2, 4, 3, 1],
[0, 6, 5, 3, 8, 7, 1, 2, 9, 4],
[9, 7, 8, 6, 3, 0, 1, 5, 2, 4],
[1, 0, 5, 9, 2, 7, 3, 6, 4, 8],
[6, 2, 9, 4, 1, 0, 8, 5, 3, 7]
]
function IpsEncodeString(source) {
var i, j, k;
source = source.replace(/\D/g,"");
result = '';
i, j = 0;
for (i = 1; i <= source.length-1; i++){
k = mas1[j, parseInt(source[i])];
result += k;
j++;
if (j >= 10){
j = 0
}
}
return result
}