File tree Expand file tree Collapse file tree 1 file changed +5
-19
lines changed Expand file tree Collapse file tree 1 file changed +5
-19
lines changed Original file line number Diff line number Diff line change
1
+ // Package rot13 is a simple letter substitution cipher that replaces a letter with the 13th letter after it in the alphabet.
2
+ // ref: https://en.wikipedia.org/wiki/ROT13
1
3
package rot13
2
4
3
5
import (
4
- "bytes"
5
- "strings"
6
+ "TheAlgorithms/Go/ciphers/caesar"
6
7
)
7
8
9
+ // rot13 is a special case, which is fixed the shift of 13, of the Caesar cipher
8
10
func rot13 (input string ) string {
9
- var outputBuffer bytes.Buffer
10
- for _ , r := range strings .ToLower (input ) {
11
- newByte := int (r )
12
-
13
- if newByte >= 'a' && newByte <= 'z' {
14
- newByte += 13
15
-
16
- if newByte > 'z' {
17
- newByte -= 26
18
- } else if newByte < 'a' {
19
- newByte += 26
20
- }
21
- }
22
-
23
- outputBuffer .WriteString (string (newByte ))
24
- }
25
- return outputBuffer .String ()
11
+ return caesar .NewCaesar ().Encrypt (input , 13 )
26
12
}
You can’t perform that action at this time.
0 commit comments