added rail fence and split transposition ciphers
This commit is contained in:
parent
cfd0277719
commit
3a3d52aca1
@ -5,7 +5,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Transpose(input string) string {
|
func TransposeRandom(input string) string {
|
||||||
shuffle := ""
|
shuffle := ""
|
||||||
list := rand.Perm(len(input))
|
list := rand.Perm(len(input))
|
||||||
fmt.Println(list)
|
fmt.Println(list)
|
||||||
@ -14,3 +14,32 @@ func Transpose(input string) string {
|
|||||||
}
|
}
|
||||||
return shuffle
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user