diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-08-14 14:22:57 -0400 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-08-14 14:22:57 -0400 |
commit | 295d782194e7495b4d577c16debbf62506674916 (patch) | |
tree | a03eef3113b0d8147eb274f75bdeea32a2d03837 | |
parent | 1ed0e523773ef996693f6f5a7e616da6d4181ca2 (diff) |
challenge: do challenge 39v0.39.0
-rw-r--r-- | challenge/c39.go | 53 | ||||
-rw-r--r-- | cryptopals.go | 2 |
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge/c39.go b/challenge/c39.go new file mode 100644 index 0000000..e4c0bf7 --- /dev/null +++ b/challenge/c39.go @@ -0,0 +1,53 @@ +// Copyright © 2022 siddharth ravikumar <s@ricketyspace.net> +// SPDX-License-Identifier: ISC + +package challenge + +import ( + "fmt" + + "ricketyspace.net/cryptopals/lib" +) + +func C39() { + rsa, err := lib.RSAGenKey() + if err != nil { + fmt.Printf("gen key failed: %v", err) + } + + msg := []byte("42") + enc := rsa.Public.Encrypt(msg) + if len(enc) < 1 { + fmt.Printf("encrypt failed: %v", enc) + return + } + dec := rsa.Private.Decrypt(enc) + if !lib.BytesEqual(msg, dec) { + fmt.Printf("decrypt failed: %v", dec) + return + } + + msg = []byte("0x42") + enc = rsa.Public.Encrypt(msg) + if len(enc) < 1 { + fmt.Printf("encrypt failed: %v", enc) + return + } + dec = rsa.Private.Decrypt(enc) + if !lib.BytesEqual(msg, dec) { + fmt.Printf("decrypt failed: %v", dec) + return + } + + msg = []byte("68f13a29c10617c2c87cccb8db2d40ba05191f75f5a08978e84d829a543fa933") + enc = rsa.Public.Encrypt(msg) + if len(enc) < 1 { + fmt.Printf("encrypt failed: %v", enc) + return + } + dec = rsa.Private.Decrypt(enc) + if !lib.BytesEqual(msg, dec) { + fmt.Printf("decrypt failed: %v", dec) + return + } +} diff --git a/cryptopals.go b/cryptopals.go index 82627e0..8ff0d6c 100644 --- a/cryptopals.go +++ b/cryptopals.go @@ -96,5 +96,7 @@ func main() { challenge.C37(flag.Args()) case 38: challenge.C38(flag.Args()) + case 39: + challenge.C39() } } |