mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-03 18:58:27 +02:00
2016-day04: caesar shift algo, validating checksum
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package algos
|
||||
|
||||
// CaesarShift performs a forwards caesar shift of a given shiftAmount
|
||||
func CaesarShift(in string, shiftAmount int) string {
|
||||
var result string
|
||||
for _, char := range in {
|
||||
// char to ascii number
|
||||
ascii := int(char) - int('a')
|
||||
ascii += shiftAmount
|
||||
ascii %= 26
|
||||
ascii += int('a')
|
||||
result += string(rune(ascii))
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user