Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. int count = 0;
  2. long a = 0L;
  3. long b = 0L;
  4. long overflow = 0L;
  5. long max = 4294967296L;
  6. long c = 0;
  7.  
  8. if (str.length() != 7) {
  9. System.out.println("- Failed clientcode proof length test: " + str + " -> length: " + str.length());
  10. return false;
  11. }
  12.  
  13. while (count < str.length() -1) {
  14.  
  15. a = c << 4;
  16. b = str.getBytes()[count];
  17. c = a ^ b;
  18. overflow = c >> 32;
  19. c = c & 0xFFFFFFFF;
  20. c = c ^ overflow;
  21.  
  22. System.out.printf( "a=%15d %45sn", a, Long.toBinaryString( a ));
  23. System.out.printf( "b=%15d %45sn", b, Long.toBinaryString( b ));
  24. System.out.printf( "c=%15d %45sn", c, Long.toBinaryString( c ));
  25. System.out.println( "---------------------------------------------------------------");
  26. count++;
  27. }
  28.  
  29. if (c > 2147483647) {
  30. c = c - max;
  31. } else if (c >= 32768 && c <= 65535) {
  32. c = c - 65536;
  33. } else if (c >= 128 && c <= 255) {
  34. c = c - 256;
  35. }
  36.  
  37. String strTekenreeks = "BCDFGHJKMNPQRSTWXYZ23456789";
  38. // Java result
  39. // int intModulus = toIntExact(c) % 27;
  40. int intModulus = (int)c % 27;
  41. String strCalculatedChar = strTekenreeks.substring(intModulus, intModulus + 1);
  42. System.out.printf("Java checksum : %s, modulo %d=%d, %s, %sn", c, 27, toIntExact(c) % 27, strTekenreeks, strCalculatedChar);
  43.  
  44. // T-SQl result
  45. intModulus = 158510959 % 27;
  46. strCalculatedChar = strTekenreeks.substring(intModulus, intModulus + 1);
  47. System.out.printf("T-SQL checksum : %s, modulo %d=%d, %s, %sn", "158510959", 27, toIntExact(158510959) % 27, strTekenreeks, strCalculatedChar);
  48. //
  49. String strLastChar = str.substring(6, 7);
  50. if (strLastChar.equals(strCalculatedChar)) {
  51. System.out.println("- Passed clientcode proof");
  52. return true;
  53. } else {
  54. System.out.println("- Failed clientcode proof: " + str + ", calculated character: " + strCalculatedChar);
  55. return false;
  56. // return true;
  57. }
  58.  
  59. File: S5WKBCK_testcodeS5WKBCK.pdf
  60. a= 0 0
  61. b= 83 1010011
  62. c= 83 1010011
  63. ---------------------------------------------------------------
  64. a= 1328 10100110000
  65. b= 53 110101
  66. c= 1285 10100000101
  67. ---------------------------------------------------------------
  68. a= 20560 101000001010000
  69. b= 87 1010111
  70. c= 20487 101000000000111
  71. ---------------------------------------------------------------
  72. a= 327792 1010000000001110000
  73. b= 75 1001011
  74. c= 327739 1010000000000111011
  75. ---------------------------------------------------------------
  76. a= 5243824 10100000000001110110000
  77. b= 66 1000010
  78. c= 5243890 10100000000001111110010
  79. ---------------------------------------------------------------
  80. a= 83902240 101000000000011111100100000
  81. b= 67 1000011
  82. c= 83902307 101000000000011111101100011
  83. ---------------------------------------------------------------
  84. Java binary_checksum() : 83902307, modulo 27=23, BCDFGHJKMNPQRSTWXYZ23456789, 6
  85. - Failed proof: S5WKBCK, calculated character: 6
  86.  
  87. T-SQL binary_checksum() : 158510959, modulo 27=7, BCDFGHJKMNPQRSTWXYZ23456789, K
  88. - Passed proof: S5WKBCK, calculated character: K
Add Comment
Please, Sign In to add comment