Encrypt encrypts based on the RSA algorithm - uses modular exponentitation in math directory
(message []rune, publicExponent, modulus int64)
| 28 | |
| 29 | // Encrypt encrypts based on the RSA algorithm - uses modular exponentitation in math directory |
| 30 | func Encrypt(message []rune, publicExponent, modulus int64) ([]rune, error) { |
| 31 | var encrypted []rune |
| 32 | |
| 33 | for _, letter := range message { |
| 34 | encryptedLetter, err := modular.Exponentiation(int64(letter), publicExponent, modulus) |
| 35 | if err != nil { |
| 36 | return nil, ErrorFailedToEncrypt |
| 37 | } |
| 38 | encrypted = append(encrypted, rune(encryptedLetter)) |
| 39 | } |
| 40 | |
| 41 | return encrypted, nil |
| 42 | } |
| 43 | |
| 44 | // Decrypt decrypts encrypted rune slice based on the RSA algorithm |
| 45 | func Decrypt(encrypted []rune, privateExponent, modulus int64) (string, error) { |