Skip to content

Instantly share code, notes, and snippets.

@Bablzz
Last active September 16, 2019 07:48
Show Gist options
  • Save Bablzz/08e4588d9c84cc409f359c33114f1fb9 to your computer and use it in GitHub Desktop.
Save Bablzz/08e4588d9c84cc409f359c33114f1fb9 to your computer and use it in GitHub Desktop.
Caesar cypher
package main
import "fmt"
var mes = "test cypeher with digit 6"
func main() {
bs := ([]byte)(mes)
cyp := make([]byte, len(bs))
j := 0
key := (byte)(2)
for i := range bs {
if bs[i] != 32 {
bs[i] = bs[i] + key
}
}
for i := len(bs) - 1; i >= 0; i-- {
cyp[j] = bs[i]
j++
}
fmt.Printf("%v\n", string(bs))
fmt.Printf("%v", string(cyp))
}
// Output =>
// vguv e{rgjgt ykvj fkikv 8
// 8 vkikf jvky tgjgr{e vugv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment