Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package crccheck;
- /**
- *
- * @author Vark
- */
- public class Crccheck {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- String poly = "1010000001010011";
- byte[] bytes = ("abcdefghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345a"+
- "bcdefghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345ab"+
- "cdefghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345abc"+
- "defghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345abcd"+
- "efghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345abcde"+
- "fghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345......"+
- "................................................................"+
- "........................................................").getBytes();
- StringBuilder sb = new StringBuilder();
- //sb.append("1101001101010");
- for(int i = 0; i < 504; i++){ //can be 64 also
- String s = Integer.toBinaryString(bytes[i]);
- while (s.length() < 8){
- s = "0" + s;
- }
- sb.append(s);
- }
- sb.append("000000000000000");
- //System.out.println(sb);
- //System.out.println(sb.length());
- while(sb.charAt(0) == '0'){
- sb = sb.delete(0, 1);
- }
- int index = 1;
- try{
- while(sb.length() > poly.length()){
- String str = "";
- for(int i = 0; i < poly.length(); i++){
- if (poly.charAt(i) == sb.charAt(i)){
- str += "0";
- } else {
- str += "1";
- }
- }
- sb.replace(0, poly.length(), str);
- //System.out.println(sb.length());
- while(sb.charAt(0) == '0' && sb.length() > 16){
- sb = sb.delete(0, 1);
- index++;
- }
- index++;
- }
- System.out.println(sb);
- } catch(Exception e){
- e.printStackTrace();
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement