File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ function Show-Usage () {
2+ Write-Host " Usage: please provide a mode and a string to encode/decode"
3+ Exit 1
4+ }
5+
6+ function Get-Base64Encode ([string ]$Str ) {
7+ $Bytes = [Text.Encoding ]::Ascii.GetBytes($Str )
8+ [Convert ]::ToBase64String($Bytes )
9+ }
10+
11+ function Get-Base64Decode ([string ]$Str ) {
12+ $Bytes = [Convert ]::FromBase64String($Str )
13+ [Text.Encoding ]::Ascii.GetString($Bytes )
14+ }
15+
16+ if ($args.Length -lt 2 -or -not $args [1 ]) {
17+ Show-Usage
18+ }
19+
20+ $Mode = $args [0 ]
21+ $Str = $args [1 ]
22+ switch ($Mode ) {
23+ " encode" {
24+ $Result = Get-Base64Encode ($Str )
25+ }
26+ " decode" {
27+ try {
28+ $Result = Get-Base64Decode ($Str )
29+ } catch [Management.Automation.MethodInvocationException ] {
30+ Show-Usage
31+ }
32+ }
33+ default {
34+ Show-Usage
35+ }
36+ }
37+
38+ Write-Host $Result
You can’t perform that action at this time.
0 commit comments