Substitution cipher: Difference between revisions
Content added Content deleted
(Added Sidef) |
(Added Go) |
||
Line 677: | Line 677: | ||
Click here to know more. |
Click here to know more. |
||
</pre> |
|||
=={{header|Go}}== |
|||
{{trans|Kotlin}} |
|||
<lang go>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)) |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Encoded: 2bu]E,KHm].Tdc|]4d\]),8M>]dQuT]<bu]U31C]Idf_]cbd].3Tm>]+ZzL]Ud,IUCk |
|||
Decoded: The quick brown fox jumps over the lazy dog, who barks VERY loudly! |
|||
</pre> |
</pre> |
||