Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package crccheck;
  7.  
  8. /**
  9. *
  10. * @author Vark
  11. */
  12. public class Crccheck {
  13. /**
  14. * @param args the command line arguments
  15. */
  16. public static void main(String[] args) {
  17.  
  18. String poly = "1010000001010011";
  19.  
  20. byte[] bytes = ("abcdefghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345a"+
  21. "bcdefghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345ab"+
  22. "cdefghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345abc"+
  23. "defghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345abcd"+
  24. "efghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345abcde"+
  25. "fghijklmnopqrstuvwxyz12345-ABCDEFGHIJKLMNOPQRSTUVWXYZ12345......"+
  26. "................................................................"+
  27. "........................................................").getBytes();
  28. StringBuilder sb = new StringBuilder();
  29. //sb.append("1101001101010");
  30. for(int i = 0; i < 504; i++){ //can be 64 also
  31. String s = Integer.toBinaryString(bytes[i]);
  32. while (s.length() < 8){
  33. s = "0" + s;
  34. }
  35. sb.append(s);
  36. }
  37. sb.append("000000000000000");
  38. //System.out.println(sb);
  39. //System.out.println(sb.length());
  40. while(sb.charAt(0) == '0'){
  41. sb = sb.delete(0, 1);
  42. }
  43. int index = 1;
  44. try{
  45. while(sb.length() > poly.length()){
  46.  
  47. String str = "";
  48. for(int i = 0; i < poly.length(); i++){
  49. if (poly.charAt(i) == sb.charAt(i)){
  50. str += "0";
  51. } else {
  52. str += "1";
  53. }
  54.  
  55.  
  56. }
  57. sb.replace(0, poly.length(), str);
  58. //System.out.println(sb.length());
  59. while(sb.charAt(0) == '0' && sb.length() > 16){
  60. sb = sb.delete(0, 1);
  61. index++;
  62. }
  63.  
  64. index++;
  65.  
  66. }
  67. System.out.println(sb);
  68. } catch(Exception e){
  69. e.printStackTrace();
  70. System.exit(0);
  71. }
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement