MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / Decrypt

Function Decrypt

cipher/transposition/transposition.go:83–107  ·  view source on GitHub ↗
(text []rune, keyWord string)

Source from the content-addressed store, hash-verified

81}
82
83func Decrypt(text []rune, keyWord string) ([]rune, error) {
84 key := getKey(keyWord)
85 textLength := len(text)
86 if textLength <= 0 {
87 return nil, ErrNoTextToEncrypt
88 }
89 keyLength := len(key)
90 if keyLength <= 0 {
91 return nil, ErrKeyMissing
92 }
93 n := textLength % keyLength
94 for i := 0; i < keyLength-n; i++ {
95 text = append(text, placeholder)
96 }
97 var result []rune
98 for i := 0; i < textLength; i += keyLength {
99 transposition := make([]rune, keyLength)
100 for j := 0; j < keyLength; j++ {
101 transposition[j] = text[i+key[j]-1]
102 }
103 result = append(result, transposition...)
104 }
105 result = []rune(strings.TrimRight(string(result), string(placeholder)))
106 return result, nil
107}

Callers 3

TestDecryptFunction · 0.70
TestEncryptDecryptFunction · 0.70
FuzzTranspositionFunction · 0.70

Calls 1

getKeyFunction · 0.85

Tested by 3

TestDecryptFunction · 0.56
TestEncryptDecryptFunction · 0.56
FuzzTranspositionFunction · 0.56