Created
November 16, 2024 19:43
-
-
Save thelissimus/de30b456581824661a12b6a0794bc38d to your computer and use it in GitHub Desktop.
Vigenère Cipher exntended to support UTF, implemented in Go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ( | |
| "fmt" | |
| "strings" | |
| ) | |
| func cypher(str string, key string) string { | |
| s, ix := new(strings.Builder), 0 | |
| for _, cs := range str { | |
| s.WriteRune(cs + rune(key[ix%len(key)])) | |
| ix++ | |
| } | |
| return s.String() | |
| } | |
| func decypher(str string, key string) string { | |
| s, ix := new(strings.Builder), 0 | |
| for _, cs := range str { | |
| s.WriteRune(cs - rune(key[ix%len(key)])) | |
| ix++ | |
| } | |
| return s.String() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment