forked from stevencohn/WindowsPowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertFrom-BinHex.ps1
44 lines (36 loc) · 887 Bytes
/
ConvertFrom-BinHex.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<#
.SYNOPSIS
Convert a BinHex encoded string back to its original string value.
.PARAMETER Hex
A string specifying a BinHex encoded string.
.PARAMETER Unicode
Use unicode encoding. Default is to use ASCII encoding.
#>
param(
[string] $Hex,
[switch] $Unicode
)
Begin
{
function Decode
{
$data = [System.Convert]::FromBase64String($hex)
if ($Unicode)
{
return [System.Text.UnicodeEncoding]::Unicode.GetString($data)
}
return [System.Text.ASCIIEncoding]::ASCII.GetString($data)
}
}
Process
{
Decode
}
<#
#Example of converting ASCII to Unicode; can reverse it to convert Unicode to ASCII
$bytes = [System.Text.Encoding]::Convert( `
[System.Text.Encoding]::ASCII, `
[System.Text.Encoding]::Unicode, `
[System.Text.Encoding]::ASCII.GetBytes('this is a string'))
$text = [System.Text.UnicodeEncoding]::Unicode.GetString($bytes)
#>