Guest User

Untitled

a guest
Jun 17th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function test {
  2.     [CmdletBinding()]
  3.     Param(
  4.         [string]$string
  5.     )
  6.    
  7.     $checksumString = $string[-4..-1]
  8.     $checksumBytes = $(
  9.         [System.Convert]::ToByte(($checksumString[2,3] -join ''),16)
  10.         [System.Convert]::ToByte(($checksumString[0,1] -join ''),16)
  11.     )
  12.     [uint16]$checksumValue = [System.BitConverter]::TouInt16($checksumBytes,0)
  13.  
  14.     Write-Verbose $checksumValue
  15.  
  16.     $data = $string.Substring(0,($string.Length -4))
  17.     $dataBytes = [System.Text.Encoding]::ASCII.GetBytes($data)
  18.     [uint16]$datasumvalue = $dataBytes | Measure-Object -Sum | Select-Object -ExpandProperty Sum
  19.  
  20.     Write-Verbose $datasumvalue
  21.  
  22.     ($datasumvalue + $checksumValue - [uint16]::MaxValue) -eq 0
  23. }
Advertisement
Add Comment
Please, Sign In to add comment