Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test {
- [CmdletBinding()]
- Param(
- [string]$string
- )
- $checksumString = $string[-4..-1]
- $checksumBytes = $(
- [System.Convert]::ToByte(($checksumString[2,3] -join ''),16)
- [System.Convert]::ToByte(($checksumString[0,1] -join ''),16)
- )
- [uint16]$checksumValue = [System.BitConverter]::TouInt16($checksumBytes,0)
- Write-Verbose $checksumValue
- $data = $string.Substring(0,($string.Length -4))
- $dataBytes = [System.Text.Encoding]::ASCII.GetBytes($data)
- [uint16]$datasumvalue = $dataBytes | Measure-Object -Sum | Select-Object -ExpandProperty Sum
- Write-Verbose $datasumvalue
- ($datasumvalue + $checksumValue - [uint16]::MaxValue) -eq 0
- }
Advertisement
Add Comment
Please, Sign In to add comment