https://exercism.org/tracks/go/exercises/affine-cipher
Hi, I'd really appreciate any help, no idea what's wrong with the calculation in decValue. This is the Decrypt method. Based on the Decryption formula in the link It tries to compute the plaintext based on multiple modular inverse of a, corresponding value of the ciphertext letter, b and m (26)
for _, char := range text {
// D(y) = (a^-1)(y - b) mod m
encryptedLetterValue := letterMap[char] // the number that maps to the encrypted letter
fmt.Printf("The value of the encrypted letter %c is %d\n", char, encryptedLetterValue)
// a^-1 = FindMMIOfA(a)
// TOFIX: what is wrong with this formula? it returns negative values which then maps to garbled output. See the test outputs. I'm sure it's not an order of operations problem.
decValue := (FindMMIOfA(a) * (encryptedLetterValue - b)) % 26
// we then retrieve the corresponding letter from the codeMap based on its value
plainText.WriteString(string(codeMap[decValue]))
fmt.Printf("plaintext is %s\n", plainText.String())