Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: initial interface draft and basic RSA implementation #2

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/RSA.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
struct RSAKey
key_module::BigInt
key_component::BigInt
type:: AsymetricKeyType
end

function RSAStep(m::BigInt, e::BigInt, n::BigInt)
return (m ^ e) % n
end

function encrypt(msg, key::RSAKey)
return RSAStep(msg, key.key_component, key.key_module)
end

# Decryption using the private key
function decrypt(msg, key::RSAKey)
return RSAStep(msg, key.key_component, key.key_module)
end
4 changes: 3 additions & 1 deletion src/ToyPublicKeys.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module ToyPublicKeys

# Write your package code here.
@enum AsymetricKeyType public_key private_key

include("RSA.jl")
export RSAKey, encrypt, decrypt
end
15 changes: 14 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,18 @@ using ToyPublicKeys
using Test

@testset "ToyPublicKeys.jl" begin
# Write your tests here.
n = big"3233" # Example modulus
e = big"17" # Example public exponent
d = big"2753" # Example private exponent

public_key = ToyPublicKeys.RSAKey(n, e, ToyPublicKeys.public_key)
private_key = ToyPublicKeys.RSAKey(n, d, ToyPublicKeys.private_key)
msg = big"123"

encrypted = ToyPublicKeys.encrypt(msg, public_key)
println("Encrypted Message: $encrypted")

decrypted = ToyPublicKeys.decrypt(encrypted, private_key)
println("Decrypted Message: $decrypted")
encrypted == msg
end
Loading