Skip to content

Commit 2a71f7b

Browse files
committed
Fix Ceaser Cipher
1 parent efa32bd commit 2a71f7b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

ciphers/caesar/CaesarCipher.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
package main
2-
1+
package ceaser
2+
33
import (
44
"bytes"
55
"flag"
66
"fmt"
77
"strings"
88
)
9-
9+
1010
func main() {
1111
cipherKey := flag.Int("c", 0, "Cipher shift amount (-26 - 26)")
1212
input := flag.String("i", "", "Input")
1313
flag.Parse()
14-
14+
1515
if *cipherKey > 26 || *cipherKey < -26 {
1616
flag.PrintDefaults()
1717
} else {
1818
fmt.Println(caesarCipher(*input, *cipherKey))
1919
}
20-
20+
2121
}
22-
22+
2323
func caesarCipher(input string, key int) string {
2424
var outputBuffer bytes.Buffer
2525
for _, r := range strings.ToLower(input) {
26-
newByte := int(r)
27-
26+
newByte := byte(r)
27+
2828
if newByte >= 'a' && newByte <= 'z' {
29-
newByte += key
30-
29+
newByte += byte(key)
30+
3131
if newByte > 'z' {
3232
newByte -= 26
3333
} else if newByte < 'a' {
3434
newByte += 26
35-
}
35+
}
3636
}
37-
37+
3838
outputBuffer.WriteString(string(newByte))
3939
}
4040
return outputBuffer.String()
41-
}
41+
}

ciphers/caesar/caesar_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package ceaser
22

33
import (
44
"testing"

0 commit comments

Comments
 (0)