File tree Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Original file line number Diff line number Diff line change 1
- package main
2
-
1
+ package ceaser
2
+
3
3
import (
4
4
"bytes"
5
5
"flag"
6
6
"fmt"
7
7
"strings"
8
8
)
9
-
9
+
10
10
func main () {
11
11
cipherKey := flag .Int ("c" , 0 , "Cipher shift amount (-26 - 26)" )
12
12
input := flag .String ("i" , "" , "Input" )
13
13
flag .Parse ()
14
-
14
+
15
15
if * cipherKey > 26 || * cipherKey < - 26 {
16
16
flag .PrintDefaults ()
17
17
} else {
18
18
fmt .Println (caesarCipher (* input , * cipherKey ))
19
19
}
20
-
20
+
21
21
}
22
-
22
+
23
23
func caesarCipher (input string , key int ) string {
24
24
var outputBuffer bytes.Buffer
25
25
for _ , r := range strings .ToLower (input ) {
26
- newByte := int (r )
27
-
26
+ newByte := byte (r )
27
+
28
28
if newByte >= 'a' && newByte <= 'z' {
29
- newByte += key
30
-
29
+ newByte += byte ( key )
30
+
31
31
if newByte > 'z' {
32
32
newByte -= 26
33
33
} else if newByte < 'a' {
34
34
newByte += 26
35
- }
35
+ }
36
36
}
37
-
37
+
38
38
outputBuffer .WriteString (string (newByte ))
39
39
}
40
40
return outputBuffer .String ()
41
- }
41
+ }
Original file line number Diff line number Diff line change 1
- package main
1
+ package ceaser
2
2
3
3
import (
4
4
"testing"
You can’t perform that action at this time.
0 commit comments