Substitution cipher: Difference between revisions

(Undo revision 324776 by Drkameleon (talk))
Line 92:
enc: encode s
print ["encoded:" enc]
print ["decoded:" decode enc]</lang>
 
 
; 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}}
1,532

edits