Decrypt decrypts with polybius encryption
(text string)
| 63 | |
| 64 | // Decrypt decrypts with polybius encryption |
| 65 | func (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 | |
| 78 | func (p *Polybius) encipher(char rune) (string, error) { |
| 79 | index := strings.IndexRune(p.key, char) |