MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Decrypt

Method Decrypt

cipher/polybius/polybius.go:65–76  ·  view source on GitHub ↗

Decrypt decrypts with polybius encryption

(text string)

Source from the content-addressed store, hash-verified

63
64// Decrypt decrypts with polybius encryption
65func (p *Polybius) Decrypt(text string) (string, error) {
66 chars := []rune(strings.ToUpper(text))
67 decryptedText := ""
68 for i := 0; i < len(chars); i += 2 {
69 decryptedChar, err := p.decipher(chars[i:int(math.Min(float64(i+2), float64(len(chars))))])
70 if err != nil {
71 return "", fmt.Errorf("failed decipher: %w", err)
72 }
73 decryptedText += decryptedChar
74 }
75 return decryptedText, nil
76}
77
78func (p *Polybius) encipher(char rune) (string, error) {
79 index := strings.IndexRune(p.key, char)

Callers 3

ExampleNewPolybiusFunction · 0.95
TestPolybiusDecryptFunction · 0.95
FuzzPolybiusFunction · 0.95

Calls 2

decipherMethod · 0.95
MinMethod · 0.65

Tested by 3

ExampleNewPolybiusFunction · 0.76
TestPolybiusDecryptFunction · 0.76
FuzzPolybiusFunction · 0.76