Monday, May 2, 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
}

Related Post:

0 comments:

Post a Comment

 
Copyright 2009 Information Blog
Powered By Blogger