Untitled
public class ChecksumCalculator { public String getCheckSum(String nodeId, String processId) { byte[] tabela = nodeId.getBytes(StandardCharsets.UTF_8); byte[] tabela2 = Hex.decodeHex("00070E091C1B1215383F363124232A2D70777E796C6B6265484F464154535A5DE0E7EEE9FCFBF2F5D8DFD6D1C4C3CACD90979E998C8B8285A8AFA6A1B4B3BABDC7C0C9CEDBDCD5D2FFF8F1F6E3E4EDEAB7B0B9BEABACA5A28F88818693949D9A2720292E3B3C35321F18111603040D0A5750595E4B4C45426F68616673747D7A898E878095929B9CB1B6BFB8ADAAA3A4F9FEF7F0E5E2EBECC1C6CFC8DDDAD3D4696E676075727B7C51565F584D4A4344191E171005020B0C21262F283D3A33344E49404752555C5B7671787F6A6D64633E39303722252C2B0601080F1A1D1413AEA9A0A7B2B5BCBB9691989F8A8D8483DED9D0D7C2C5CCCBE6E1E8EFFAFDF4F3"); int val = 0; for (byte b : tabela) { val ^= b & 0xFF; val &= 0xFF; val = tabela2[val] & 0xFF; if (val > 128) { val -= 256; } } val &= 0xFF; String sumaCRC8 = Integer.toHexString(val); return processId + "," + sumaCRC8 + "-" + nodeId; } }
Leave a Comment