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

Function Encrypt

cipher/rsa/rsa.go:30–42  ·  view source on GitHub ↗

Encrypt encrypts based on the RSA algorithm - uses modular exponentitation in math directory

(message []rune, publicExponent, modulus int64)

Source from the content-addressed store, hash-verified

28
29// Encrypt encrypts based on the RSA algorithm - uses modular exponentitation in math directory
30func 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
45func Decrypt(encrypted []rune, privateExponent, modulus int64) (string, error) {

Callers 2

TestEncryptDecryptFunction · 0.70
FuzzRsaFunction · 0.70

Calls 1

ExponentiationFunction · 0.92

Tested by 2

TestEncryptDecryptFunction · 0.56
FuzzRsaFunction · 0.56