Skip to content

Commit

Permalink
[FIX] Implement suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaniel27 committed Jul 2, 2024
1 parent 106a37b commit 6db6526
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions cipher/rsa/rsa2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ type rsa struct {
// New initializes the RSA algorithm
// returns the RSA object
func New() *rsa {
rsa := new(rsa)

// The following code generates keys for RSA encryption/decryption
// 1. Choose two large prime numbers, p and q and compute n = p * q
p, q := randomPrime() // p and q stands for prime numbers
Expand All @@ -51,11 +49,11 @@ func New() *rsa {
inv, _ := modular.Inverse(int64(publicKey), int64(totient))
privateKey := uint64(inv)

rsa.publicKey = publicKey
rsa.privateKey = privateKey
rsa.modulus = modulus

return rsa
return &rsa{
publicKey: publicKey,
privateKey: privateKey,
modulus: modulus,
}
}

// EncryptString encrypts the data using RSA algorithm
Expand Down Expand Up @@ -114,8 +112,8 @@ func encryptDecryptInt(e, n, data uint64) uint64 {
func randomPrime() (uint64, uint64) {
sieve := prime.SieveEratosthenes(1000)
sieve = sieve[10:] // remove first 10 prime numbers (small numbers)
index1 := rand.Intn(len(sieve) - 10)
index2 := rand.Intn(len(sieve) - 10)
index1 := rand.Intn(len(sieve))
index2 := rand.Intn(len(sieve))

for index1 == index2 {
index2 = rand.Intn(len(sieve))
Expand Down

0 comments on commit 6db6526

Please sign in to comment.