java - How do I know a Longitudinal redundancy check is correctly calculated and how is it used to ensure that data before is not corrupt? -


how know longitudinal redundancy check correctly calculated , how used ensure data before not corrupt?

this how i'm calculating right in java how know calculating correctly given data?

byte[] testmessage1 = {0x02, // stx         0x10,0x2,0xa,0x10,0x10,0x7,0x8, // data 02, a, 10, 7, 8         0x03, // etx         0x2^0xa^0x10^0x7^0x8^0x03}; // lrc calculated data (with dle removed) plus etx    public static byte calculatelrc2(byte[] bytes) {     byte checksum = 0;     (int = 1; < bytes.length - 1; i++) {         checksum ^= (bytes[i] & 0xff);               }     return checksum; } 

you looking answer of wrong question in opinion because lrc check find out weather reading data correctly or not not other way around. if want validate implementation create unit tests real examples. please remember lrc validate if data read source correct (and not tempered or faulty) lrc must available within data code make sure lrc calculating , lrc available in source matching. if in case don't have access sample data can try online tools e.g. asecuritysite.com. coming code following code working me in java validation of credit card magnetic strip read. see running online here.

string str = ";4564456445644564=1012101123456789?"; byte lrc = 0x00; byte [] binaryvalue = str.getbytes();  for(byte b : binaryvalue) {      lrc ^= b; }  // lrc msut between 48 95 lrc %= 48;  lrc += 48;  system.out.println("lrc: " + (char) lrc); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -