Advertisement
Guest User

SC1000 keygen

a guest
Dec 20th, 2021
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Base36-Encode
  2. {
  3.     param ([parameter(ValueFromPipeline = $true)][int]$base10 = "")
  4.     $alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  5.  
  6.     do {
  7.         $remainder = ($base10 % 36)
  8.         $char = $alphabet.Substring($remainder, 1)
  9.         $base36 = "$char$base36"
  10.         $base10 = ($base10 - $remainder) / 36
  11.     } while ($base10 -gt 0)
  12.    
  13.     $base36
  14.  }
  15.  
  16.  
  17.  
  18. function Reverse-String
  19. {
  20.     param ([parameter(ValueFromPipeline = $true)][string]$orig = "")
  21.     $len = $orig.Length
  22.    
  23.     for ($e = $len-1; $e -ge 0; $e--) {
  24.         $curChar =$orig[$e]
  25.         $reverted = "$reverted$curChar"
  26.     }
  27.  
  28.     $reverted
  29.  }
  30.  
  31.  
  32.  
  33.  
  34.  
  35. "----Hach-Lange SC1000 Controller keygen----"
  36.  
  37.  
  38.  
  39. "`r`n"
  40. " PART 1 of key"
  41.  
  42. $arbtrPart1_input = Read-Host -Prompt "  Arbitrary value of part 1 (10...99)"
  43. if ($arbtrPart1_input.Length -eq 0) {
  44.     $arbtrPart1 = Get-Random -Minimum 10 -Maximum 99
  45.     "  - no specified value, chosen random: $arbtrPart1"
  46. } else {
  47.     $arbtrPart1 = [int]$arbtrPart1_input
  48.     if (($arbtrPart1 -gt 99) -or ($arbtrPart1 -lt 10)) {
  49.         throw "Arbitrary value of part 1 must be between 10 and 99 including extremes"
  50.     }
  51. }
  52.  
  53. "  2nd value of part 1 is 0 -> Algorithm version 0"
  54. $algoVersion = 0
  55.  
  56.  
  57.  
  58. "`r`n"
  59. " PART 2 of key"
  60.  
  61. #NOTE - Known Feature IDs: 1 - Modbus/TCP Server
  62. #                          2 - OPC UA (on newer firmware versions only)
  63. $featureId_input = Read-Host -Prompt "  Feature ID (0...128)"
  64. if ($featureId_input.Length -eq 0) {
  65.     $featureId = 1
  66.     "  - no feature ID chosen, assuming Modbus/TCP server: feature ID 1"
  67. } else {
  68.     $featureId = [int]$featureId_input
  69.     if (($featureId -gt 128) -or ($featureId -lt 0)) {
  70.     throw "Feature ID must be between 0 and 128 including extremes"
  71.     }
  72. }
  73.  
  74. $arbtrPart2_1_input = Read-Host -Prompt "  1st arbitrary value of part 2 (0...99)"
  75. if ($arbtrPart2_1_input.Length -eq 0) {
  76.     $arbtrPart2_1 = Get-Random -Minimum 0 -Maximum 99
  77.     "  - no specified value, chosen random: $arbtrPart2_1"
  78. } else {
  79.     $arbtrPart2_1 = [int]$arbtrPart2_1_input
  80.     if (($arbtrPart2_1 -gt 99) -or ($arbtrPart2_1 -lt 0)) {
  81.         throw "1st arbitrary value of part 2 must be between 0 and 99 including extremes"
  82.     }
  83. }
  84.  
  85. $arbtrPart2_2_input = Read-Host -Prompt "  2nd arbitrary value of part 2 (0...999)"
  86. if ($arbtrPart2_2_input.Length -eq 0) {
  87.     $arbtrPart2_2 = Get-Random -Minimum 0 -Maximum 999
  88.     "  - no specified value, chosen random: $arbtrPart2_2"
  89. } else {
  90.     $arbtrPart2_2 = [int]$arbtrPart2_2_input
  91.     if (($arbtrPart2_2 -gt 999) -or ($arbtrPart2_2 -lt 0)) {
  92.         throw "2nd arbitrary value of part 2 must be between 0 and 999 including extremes"
  93.     }
  94. }
  95.  
  96. "  4th value of part 2 is 99 -> version 9.9 -> Unlimited"
  97. $version = 99
  98.  
  99.  
  100.  
  101. "`r`n"
  102. " PART 3 of key"
  103.  
  104. "  Expiry date (for calculating part 3) is 9999-10-10 -> Unlimited"
  105. $expiryDate = 99991010
  106.  
  107.  
  108.  
  109. "`r`n"
  110. " PART 4 of key"
  111.  
  112. do {
  113.     $serialNum_input = Read-Host -Prompt "  Serial number of SC1000 controller"
  114. } until ($serialNum_input.Length -gt 0)
  115. $serialNum = [long]$serialNum_input
  116.  
  117.  
  118.  
  119. $obfuscatingNumber = $arbtrPart1 * $arbtrPart2_1 * $arbtrPart2_2
  120. #some obfuscation factor made with the arbitrary values
  121.  
  122.  
  123. $part1_base10 = ($arbtrPart1 * 10) + $algoVersion
  124. $part2_base10 = (($featureId * 10000000) + ($arbtrPart2_1 * 100000) +
  125.                 ($arbtrPart2_2 * 100) + $version)
  126. $part3_base10 = $expiryDate + $obfuscatingNumber
  127. $part4_base10 = $serialNum + $obfuscatingNumber
  128.  
  129.  
  130. $part1_partial = Reverse-String (Base36-Encode $part1_base10)
  131. #NOTE: This makes 4th and 5th character of the 1st part of the key;
  132. #      the first 4 chars are the CRC16/MODBUS of the whole string
  133.  
  134. $part2 = Reverse-String (Base36-Encode $part2_base10)
  135. $part3 = Reverse-String (Base36-Encode $part3_base10)
  136. $part4 = Reverse-String ([string]$part4_base10)
  137.  
  138.  
  139. #CRC16/MODBUS calculation - to be byte-swapped
  140. #and put at the beginning of the string
  141. $buf = [byte[]][char[]]"$part1_partial$part2$part3$part4"
  142. $crc = 0xFFFF
  143.        
  144. for ($pos = 0; $pos -lt $buf.Count; $pos++) {
  145.     $crc = $crc -bxor [UInt16]$buf[$pos]
  146.     for ($i = 8; $i -ne 0; $i--) {
  147.         if (($crc -band 0x0001) -ne 0) {
  148.             $crc = ($crc -shr 1) -bxor 0xA001
  149.         } else {
  150.             $crc = $crc -shr 1
  151.         }
  152.     }
  153. }
  154.  
  155. #swap bytes, and format as hexadecimal
  156. $crc_asStr = "{0:X}" -f (([uint16]$crc -shl 8) -bor ([uint16]$crc -shr 8))
  157.  
  158.  
  159.  
  160.  
  161. "`r`n"
  162. "--> $crc_asStr$part1_partial-$part2-$part3-$part4"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement