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

Function TestRSA

cipher/rsa/rsa2_test.go:9–34  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestRSA(t *testing.T) {
10 tests := []struct {
11 name string
12 message string
13 }{
14 {
15 name: "Encrypt letter 'a' and decrypt it back",
16 message: "a",
17 },
18 {
19 name: "Encrypt 'Hello, World!' and decrypt it back",
20 message: "Hello, World!",
21 },
22 }
23
24 for _, tt := range tests {
25 t.Run(tt.name, func(t *testing.T) {
26 rsa := rsa.New()
27 encrypted := rsa.EncryptString(tt.message)
28 decrypted := rsa.DecryptString(encrypted)
29 if decrypted != tt.message {
30 t.Errorf("expected %s, got %s", tt.message, decrypted)
31 }
32 })
33 }
34}
35
36func BenchmarkRSAEncryption(b *testing.B) {
37 rsa := rsa.New()

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
EncryptStringMethod · 0.80
DecryptStringMethod · 0.80

Tested by

no test coverage detected