Here you can find the source of calculateCRC(String digitsToCheck)
private static String calculateCRC(String digitsToCheck)
//package com.java2s; /*/*from w w w . j ava 2 s . c om*/ * GovPay - Porta di Accesso al Nodo dei Pagamenti SPC * http://www.gov4j.it/govpay * * Copyright (c) 2014-2015 Link.it srl (http://www.link.it). * Copyright (c) 2014-2015 TAS S.p.A. (http://www.tasgroup.it). * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ public class Main { private static String calculateCRC(String digitsToCheck) { int sumOdd = 0; int sumEven = 0; for (int i = digitsToCheck.length() - 1; i >= 0; i--) { char c = digitsToCheck.charAt(i); Integer num = Integer.parseInt(Character.toString(c)); if (isOdd(digitsToCheck.length() - i)) sumOdd += num; else sumEven += num; } int sumTot = sumEven + (sumOdd * 3); int crcInt; for (crcInt = 0; ((sumTot + crcInt) % 10) != 0; crcInt++) ; return String.valueOf(crcInt); } private static boolean isOdd(int i) { return (i % 2) != 0; } }