Senin, 02 Mei 2016

PowerShell v2 Function ConvertFrom Rot13

Here is a quick function to convert ROT13 values (check them out here if you dont know what it is) for PowerShell. No encoding, purely decoding:
function ConvertFrom-Rot13
{
     [CmdletBinding()]
     param(
          [Parameter(
              Mandatory = $true,
              ValueFromPipeline = $true
          )]
          [String]
          $rot13string
     )
    
     [String] $string = $null;
     $rot13string.ToCharArray() |
     ForEach-Object{
          Write-Verbose"$($_): $([int] $_)"
          if((([int] $_ -ge 97) -and ([int] $_ -le 109)) -or (([int] $_ -ge 65) -and ([int] $_ -le 77)))
          {
              $string += [char] ([int] $_ + 13);
          }
          elseif((([int] $_ -ge 110) -and ([int] $_ -le 122)) -or (([int] $_ -ge 78) -and ([int] $_ -le 90)))
          {
              $string += [char] ([int] $_ - 13);
          }
          else
          {
              $string += $_
          }
     }
     $string
}

lamsim

About lamsim

Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.

Subscribe to this Blog via Email :