-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rewrite rot13 title and description
Fixes #46
- Loading branch information
Showing
4 changed files
with
75 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package processors | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ROT13 converts string with ROT13 cypher. | ||
// https://en.wikipedia.org/wiki/ROT13 | ||
type ROT13 struct{} | ||
|
||
func (p ROT13) Name() string { | ||
return "rot13" | ||
} | ||
|
||
func (p ROT13) Alias() []string { | ||
return []string{"rot13-encode", "rot13-decode", "rot13-enc", "rot13-dec"} | ||
} | ||
|
||
func (p ROT13) Transform(data []byte, _ ...Flag) (string, error) { | ||
return strings.Map(rot13, string(data)), nil | ||
} | ||
|
||
func (p ROT13) Flags() []Flag { | ||
return nil | ||
} | ||
|
||
func (p ROT13) Title() string { | ||
title := "ROT13 Letter Substitution" | ||
return fmt.Sprintf("%s (%s)", title, p.Name()) | ||
} | ||
|
||
func (p ROT13) Description() string { | ||
return "Cipher/Decipher your text with ROT13 letter substitution" | ||
} | ||
|
||
func (p ROT13) FilterValue() string { | ||
return p.Title() | ||
} | ||
|
||
// rot13 private helper function for converting rune into rot13. | ||
func rot13(r rune) rune { | ||
if r >= 'a' && r <= 'z' { | ||
// Rotate lowercase letters 13 places. | ||
if r >= 'm' { | ||
return r - 13 | ||
} | ||
|
||
return r + 13 | ||
} else if r >= 'A' && r <= 'Z' { | ||
// Rotate uppercase letters 13 places. | ||
if r >= 'M' { | ||
return r - 13 | ||
} | ||
|
||
return r + 13 | ||
} | ||
// Do nothing. | ||
return r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters