added rail fence and split transposition ciphers

This commit is contained in:
Derek McQuay 2016-02-12 09:35:30 -08:00
parent cfd0277719
commit 3a3d52aca1
1 changed files with 30 additions and 1 deletions

View File

@ -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
}