Skip to content

Commit 59b4ff8

Browse files
authored
fix rot13 content (#262)
1 parent 736a23e commit 59b4ff8

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

ciphers/rot13/rot13.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
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
13
package rot13
24

35
import (
4-
"bytes"
5-
"strings"
6+
"TheAlgorithms/Go/ciphers/caesar"
67
)
78

9+
// rot13 is a special case, which is fixed the shift of 13, of the Caesar cipher
810
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)
2612
}

0 commit comments

Comments
 (0)