scripting games 2007 events 7 and 8

Event 7

Event 7 was to write a script that encrypts and decrypts a document. The encryption algorithm was totally up to the author, but it had to be built-in to Windows. I went with a simple ROT13 scheme.

if ($args -eq "e") {
    $null | out-file Encoded.txt
    $contents = get-content "alice2.txt"
    $total = ""
    foreach ($x in $contents) {
        $line = ""
        for ($i = 0; $i -lt $x.length; $i++) {
            $char = [int]$x[$i]
            if ($char -ge 65) {
                if ($char -le 90) {
                    $char += 13
                    if ($char -gt 90) {
                        $char = $($char - 90) + 65
                    }
                }
            }

            if ($char -ge 97) {
                if ($char -le 122) {
                    $char += 13
                    if ($char -gt 122) {
                        $char = $($char -122) + 97
                    }
                }
            }

            $line += [char]$char
        }

        $line | out-file -append Encoded.txt
    }
    } elseif ($args -eq "d") {
    $contents = get-content "Encoded.txt"
    $total = ""
    foreach ($x in $contents) {
        $line = ""
        for ($i = 0; $i -lt $x.length; $i++) {
            $char = [int]$x[$i]
            if ($char -ge 65) {
                if ($char -le 90) {
                    $char -= 13
                    if ($char -lt 65) {
                        $char = 90 - $(65 - $char)
                    }
                }
            }

            if ($char -ge 97) {
                if ($char -le 122) {
                    $char -= 13
                    if ($char -lt 97) {
                        $char = 122 - $(97 - $char)
                    }
                }
            }

            $line += [char]$char
        }

        $line
    }
}

Event 8

Event 8 was just a simple quiz on syntax. Nothing to see here, move along.