From 3a3d52aca13341ad0bf976c67ca24000e1c9ede1 Mon Sep 17 00:00:00 2001 From: derek mcquay Date: Fri, 12 Feb 2016 09:35:30 -0800 Subject: [PATCH] added rail fence and split transposition ciphers --- psyfer/transposition.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/psyfer/transposition.go b/psyfer/transposition.go index 54c8a0c..4b097dd 100644 --- a/psyfer/transposition.go +++ b/psyfer/transposition.go @@ -5,7 +5,7 @@ import ( "math/rand" ) -func Transpose(input string) string { +func TransposeRandom(input string) string { shuffle := "" list := rand.Perm(len(input)) fmt.Println(list) @@ -14,3 +14,32 @@ func Transpose(input string) string { } return shuffle } + +func TransposeRailFence(input string) string { + rf := "" + for i := 0; i < len(input); i += 2 { + rf += string(input[i]) + } + for i := 1; i < len(input); i += 2 { + rf += string(input[i]) + } + return rf +} + +func TransposeSplit(input string) string { + split := "" + length := len(input) + first := input[:length/2] + second := input[length/2:] + if length%2 == 0 { + for i, _ := range first { + split += string(first[i]) + string(second[i]) + } + } else { + for i, _ := range first { + split += string(first[i]) + string(second[i]) + } + split += string(second[len(second)-1]) + } + return split +}