捐血一袋救人一命

2020年12月3日 星期四

使用 PowerShell 對文字進行Escape編碼、Unescape解碼

 這個編碼解碼結果,與 JavaScript Escape() Unescape() 相同

 

$Original = 'Instead of going back to business as usual, Uber is taking this moment as an opportunity to reduce our environmental impact.The company said in a press release.[p]Uber 在新聞稿中表示:「Uber並沒有像往常一樣重返市場,而是以此為契機,減少對環境的影響。」'

$Encode = ""

$Alphabet = @(42,43,45,46,47,48,49,50,51,52,53,54,55,56,57,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122)

$Symbol = @(0,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,44,58,59,60,61,62,63,91,92,93,94,96,123,124,125,126,127)

# 編碼文字

for($i = 0; $i -lt $Original.Length; $i++){

    If($([int]$($Original[$i])) -in $Alphabet){

        $Encode += $Original[$i]

    }ElseIf($([int]$($Original[$i])) -in $Symbol){

        $Encode += [System.String]::Format("%{0:X2}", [int]$Original[$i])

    }Else{

        $Encode += [System.String]::Format("%u{0:X4}", [int]$Original[$i])

    }

}

Write-host $Encode

Write-Host "`r`n"

# 還原文字

Add-Type -AssemblyName System.Web

[System.Web.HttpUtility]::UrlDecode($Encode)

0 意見: