Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Substitution-cipher/Go/substitution-cipher.go
Normal file
31
Task/Substitution-cipher/Go/substitution-cipher.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var key = "]kYV}(!7P$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ"
|
||||
|
||||
func encode(s string) string {
|
||||
bs := []byte(s)
|
||||
for i := 0; i < len(bs); i++ {
|
||||
bs[i] = key[int(bs[i]) - 32]
|
||||
}
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func decode(s string) string {
|
||||
bs := []byte(s)
|
||||
for i := 0; i < len(bs); i++ {
|
||||
bs[i] = byte(strings.IndexByte(key, bs[i]) + 32)
|
||||
}
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := "The quick brown fox jumps over the lazy dog, who barks VERY loudly!"
|
||||
enc := encode(s)
|
||||
fmt.Println("Encoded: ", enc)
|
||||
fmt.Println("Decoded: ", decode(enc))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue