Rot13 in Powershell (original) (raw)

  1. Home
  2. Programming Projects in Every Language
  3. Rot13
  4. Rot13 in Powershell

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

Rot13 in Powershell

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
    <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>R</mi><mi>e</mi><mi>s</mi><mi>u</mi><mi>l</mi><mi>t</mi><mo>=</mo><mi>s</mi><mi>w</mi><mi>i</mi><mi>t</mi><mi>c</mi><mi>h</mi><mo>−</mo><mi>r</mi><mi>e</mi><mi>g</mi><mi>e</mi><mi>x</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">Result = switch -regex (</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal" style="margin-right:0.00773em;">R</span><span class="mord mathnormal">es</span><span class="mord mathnormal">u</span><span class="mord mathnormal">lt</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.7778em;vertical-align:-0.0833em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal" style="margin-right:0.02691em;">w</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">c</span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">re</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span><span class="mopen">(</span></span></span></span>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.