summaryrefslogtreecommitdiff
path: root/caesar.go
diff options
context:
space:
mode:
Diffstat (limited to 'caesar.go')
-rw-r--r--caesar.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/caesar.go b/caesar.go
index 4829e6a..9e36d76 100644
--- a/caesar.go
+++ b/caesar.go
@@ -34,6 +34,9 @@ func (rr RuneRange) size() int {
// shift shifts r by d within the range, modulo the size of the range.
func (rr RuneRange) shift(r rune, d int) rune {
pos := int(r - rr.Start)
+ for d < 0 {
+ d = rr.size() + d
+ }
newPos := (pos + d) % rr.size()
return rr.Start + rune(newPos)
}