Rot13 in Powershell

Published on 11 May 2025 (Updated: 11 May 2025)

Welcome to the Rot13 in Powershell page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

function Show-Usage() {
    Write-Host "Usage: please provide a string to encrypt"
    Exit 1
}

function Get-Rot13([string]$Str) {
    # -regex is case-insensitve
    $Result = switch -regex ($Str.ToCharArray()) {
        "[a-m]" { [char]([byte]$_ + 13) } # A-M, a-m -> N-Z, n-z
        "[n-z]" { [char]([byte]$_ - 13) } # N-Z, n-z -> A-M, a-m
        default { $_ } # Else, don't change
    }
    -join $Result
}

if ($args.Length -lt 1 -or -not $args[0]) {
    Show-Usage
}

Write-Host (Get-Rot13($args[0]))

Rot13 in Powershell was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.