Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci authored Jul 12, 2024
1 parent 7d967a2 commit 749eed6
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,65 @@ func main() {
To encrypt a message using the public key:
```go
package main
import (
"crypto/rand"
"fmt"
"math/big"
"github.com/xtaci/hppk"
)
func main() {
privateKey, _ := hppk.GenerateKey(5)
publicKey := privateKey.PublicKey
// Generate a key pair
pk, sk, err := hppk.GenerateKey(rand.Reader, 512)
if err != nil {
fmt.Println("Error generating keys:", err)
return
}
// Message to encrypt
message := []byte("Hello, World!")
P, Q, err := privateKey.Encrypt(&publicKey, message)
// Encrypt the message
P, Q, err := hppk.Encrypt(pk, message)
if err != nil {
fmt.Println("Error encrypting message:", err)
return
}
fmt.Println("Encrypted P:", P)
fmt.Println("Encrypted Q:", Q)
}
```
### Decrypting a Message
To decrypt the encrypted values using the private key:
```go
package main
import (
"fmt"
"github.com/xtaci/hppk"
"math/big"
)
func main() {
privateKey, _ := hppk.GenerateKey(5)
publicKey := privateKey.PublicKey
message := []byte("Hello, World!")
P, Q, _ := privateKey.Encrypt(&publicKey, message)
decryptedMessage, err := privateKey.Decrypt(P, Q)
// Assuming pk, sk, P, and Q are already defined as in the encryption example
// Decrypt the message
decryptedMessage, err := sk.Decrypt(P, Q)
if err != nil {
fmt.Println("Error decrypting message:", err)
return
}
fmt.Println("Decrypted Message:", string(decryptedMessage.Bytes()))
}
```
### Signing and VerifySignature
Expand Down

0 comments on commit 749eed6

Please sign in to comment.