Rot13 in Go

Published on 28 April 2022 (Updated: 25 September 2022)

Rot13 in Go

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

Current Solution

package main

import (
	"fmt"
	"os"
	"strings"
)

func rot13(str string) string {
	return strings.Map(encryptRune, str)
}

func encryptRune(r rune) rune {
	if r >= 65 && r <= 90 {
		return (((r - 65) + 13) % 26) + 65
	} else if r >= 97 && r <= 122 {
		return (((r - 97) + 13) % 26) + 97
	} else {
		return r
	}
}

func exitWithError() {
	fmt.Println("Usage: please provide a string to encrypt")
	os.Exit(1)
}

func main() {
	if len(os.Args) != 2 {
		exitWithError()
	}

	if len(os.Args[1]) <= 0 {
	    exitWithError()
	}

	fmt.Println(rot13(os.Args[1]))
}

Rot13 in Go was written by:

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

Note: The solution shown above is the current solution in the Sample Programs repository as of Apr 06 2019 00:32:12. The solution was first committed on Mar 17 2019 19:16:07. As a result, documentation below may be outdated.

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.