File tree 3 files changed +35
-2
lines changed
3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change
1
+ struct RSAKey
2
+ key_module:: BigInt
3
+ key_component:: BigInt
4
+ type:: AsymetricKeyType
5
+ end
6
+
7
+ function RSAStep (m:: BigInt , e:: BigInt , n:: BigInt )
8
+ return (m ^ e) % n
9
+ end
10
+
11
+ function encrypt (msg, key:: RSAKey )
12
+ return RSAStep (msg, key. key_component, key. key_module)
13
+ end
14
+
15
+ # Decryption using the private key
16
+ function decrypt (msg, key:: RSAKey )
17
+ return RSAStep (msg, key. key_component, key. key_module)
18
+ end
Original file line number Diff line number Diff line change 1
1
module ToyPublicKeys
2
2
3
- # Write your package code here.
3
+ @enum AsymetricKeyType public_key private_key
4
4
5
+ include (" RSA.jl" )
6
+ export RSAKey, encrypt, decrypt
5
7
end
Original file line number Diff line number Diff line change @@ -2,5 +2,18 @@ using ToyPublicKeys
2
2
using Test
3
3
4
4
@testset " ToyPublicKeys.jl" begin
5
- # Write your tests here.
5
+ n = big " 3233" # Example modulus
6
+ e = big " 17" # Example public exponent
7
+ d = big " 2753" # Example private exponent
8
+
9
+ public_key = ToyPublicKeys. RSAKey (n, e, ToyPublicKeys. public_key)
10
+ private_key = ToyPublicKeys. RSAKey (n, d, ToyPublicKeys. private_key)
11
+ msg = big " 123"
12
+
13
+ encrypted = ToyPublicKeys. encrypt (msg, public_key)
14
+ println (" Encrypted Message: $encrypted " )
15
+
16
+ decrypted = ToyPublicKeys. decrypt (encrypted, private_key)
17
+ println (" Decrypted Message: $decrypted " )
18
+ encrypted == msg
6
19
end
You can’t perform that action at this time.
0 commit comments