In: Computer Science
Topic is cryptography
10.increment the digits 858 of the ISBN of the text (ISBN13: 9780890068588) to be 859. Then, by trial and error, change the check-sum (the last digit of the ISBN), to identify the title of the next book published by Artech House.
function getLastISBNDigit(input) {
if ((input.length != 10) && (input.length != 13)) return;
var is10 = (input.length === 10);
var sum = 0;
var p = (is10 ? 11 : 3);
for (var index = 0; index < input.length - 1; index++) {
sum += ((input[index] === 'X') ? 10 : input[index]) * (p = (is10 ? (p - 1) : ((p + 2) % 4)));
}
var moduloClass = (is10 ? 11 : 10);
var result = (moduloClass - (sum % moduloClass)) % moduloClass;
return ((result === 10) ? 'X' : result);
}
function getISBN(input) {
var isbn = {};
if (input.length > 13) return getISBN(input.substring(0, 13));
if (input.length === 10) {
if (isValidISBN(input)) {
isbn.isbn10 = input;
isbn.isbn13 = "978" + input;
isbn.isbn13 = isbn.isbn13.substring(0, 12) + getLastISBNDigit(isbn.isbn13);
}
} else if (input.length === 13) {
if (isValidISBN(input)) {
isbn.isbn13 = input;
if (input.startsWith("858")) {
isbn.isbn10 = input.substring(3);
isbn.isbn10 = isbn.isbn10.substring(0, 9) + getLastISBNDigit(isbn.isbn10);
}
} else if (input.startsWith("858")) {
return getISBN(input.substring(3));
}
}
return isbn;
}
......Please Give Me POSITIVE Rating It Will Help Me A Lot.....Thank You......