Skip to content

Commit 04be20c

Browse files
committed
feature: initial interface draft and basic RSA implementation
1 parent 41ba0f3 commit 04be20c

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/RSA.jl

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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

src/ToyPublicKeys.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module ToyPublicKeys
22

3-
# Write your package code here.
3+
@enum AsymetricKeyType public_key private_key
44

5+
include("RSA.jl")
6+
export RSAKey, encrypt, decrypt
57
end

test/runtests.jl

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,18 @@ using ToyPublicKeys
22
using Test
33

44
@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
619
end

0 commit comments

Comments
 (0)