Skip to content

Commit

Permalink
Create qrc_tests.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Sep 21, 2024
1 parent db0ca41 commit 37ac000
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions blockchain-module/qrc/qrc_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Import necessary libraries
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::io::{Read, Write};
use std::ops::{Add, Mul, Sub};
use std::vec::Vec;

// Import the QRC module
use crate::qrc::{NTRU, McEliece};

// Define the test module
#[cfg(test)]
mod tests {
// Test the NTRU algorithm
#[test]
fn test_ntru() {
// Generate a new NTRU key pair
let (ntru, _) = NTRU::new(256, 2048, 256);

// Encrypt a message using the public key
let message = vec![1, 2, 3, 4, 5];
let ciphertext = ntru.encrypt(&message);

// Decrypt the ciphertext using the private key
let plaintext = ntru.decrypt(&ciphertext);

// Verify that the decrypted plaintext matches the original message
assert_eq!(plaintext, message);
}

// Test the McEliece algorithm
#[test]
fn test_mceliece() {
// Generate a new McEliece key pair
let (mceliece, _) = McEliece::new(256, 128, 32);

// Encrypt a message using the public key
let message = vec![1, 2, 3, 4, 5];
let ciphertext = mceliece.encrypt(&message);

// Decrypt the ciphertext using the private key
let plaintext = mceliece.decrypt(&ciphertext);

// Verify that the decrypted plaintext matches the original message
assert_eq!(plaintext, message);
}
}

0 comments on commit 37ac000

Please sign in to comment.