Created
March 15, 2016 04:51
-
-
Save qguv/0fb4d500987451c80398 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| TEST_DIR="HW3-TestVectors" | |
| rm_test_files() { | |
| rm -rf \ | |
| ciphertext \ | |
| plaintext.pdf \ | |
| plaintext \ | |
| receiver_private_key \ | |
| receiver_public_key \ | |
| sender_private_key \ | |
| sender_public_key \ | |
| private_key \ | |
| public_key \ | |
| our_plaintext.pdf \ | |
| our_plaintext \ | |
| our_ciphertext | |
| } | |
| fail_test() { | |
| echo " !! Not what we expected !!" | |
| echo " $1!" | |
| } | |
| test_genkey() { | |
| echo | |
| java FEA genkey | |
| declare -a keys=("public_key" "private_key") | |
| for k in "${keys[@]}"; do | |
| if [ -f $k ]; then | |
| echo "Generated $k" | |
| else | |
| fail_test "Failed to generate $k" | |
| fi | |
| done | |
| rm_test_files | |
| } | |
| run_test() { | |
| cp -r $1/* . | |
| echo "Testing 'receive' with TA's test files" | |
| java FEA receive receiver_private_key sender_public_key ciphertext our_plaintext.pdf && | |
| if cmp plaintext.pdf our_plaintext.pdf >/dev/null 2>&1; then | |
| echo " OK!" | |
| else | |
| fail_test "Plaintexts differ" | |
| fi | |
| rm_test_files | |
| cp -r $1/* . | |
| echo "Using 'send' to create some ciphertext" | |
| java FEA send sender_private_key receiver_public_key plaintext.pdf our_ciphertext | |
| if [ -f our_ciphertext ]; then | |
| echo " OK!" | |
| else | |
| fail_test "Failed to generate ciphertext" | |
| fi | |
| echo "Testing 'receive' with the newly-created ciphertext" | |
| java FEA receive receiver_private_key sender_public_key our_ciphertext our_plaintext.pdf && | |
| if cmp plaintext.pdf our_plaintext.pdf >/dev/null 2>&1; then | |
| echo " OK!" | |
| else | |
| fail_test "Plaintexts differ" | |
| fi | |
| rm_test_files | |
| } | |
| test_own_keys() { | |
| echo "Generating some plaintext to encrypt" | |
| echo "When has justice ever been as simple as a rule book? I can't. As much as I care about you, my first duty is to the ship. Some days you get the bear, and some days the bear gets you. Mr. Crusher, ready a collision course with the Borg ship. My oath is between Captain Kargan and myself. Your only concern is with how you obey my orders. Or do you prefer the rank of prisoner to that of lieutenant? For an android with no feelings, he sure managed to evoke them in others. In all trust, there is the possibility for betrayal. Captain, why are we out here chasing comets? Some days you get the bear, and some days the bear gets you. Maybe if we felt any human loss as keenly as we feel one of those close to us, human history would be far less bloody." > plaintext | |
| echo "Generating some keys to test with" | |
| # sender keypair | |
| java FEA genkey | |
| mv {,sender_}public_key | |
| mv {,sender_}private_key | |
| # receiver keypair | |
| java FEA genkey | |
| mv {,receiver_}public_key | |
| mv {,receiver_}private_key | |
| echo "Encrypting our file" | |
| java FEA send sender_private_key receiver_public_key plaintext ciphertext | |
| if [ -f ciphertext ]; then | |
| echo " OK!" | |
| else | |
| fail_test "Failed to generate ciphertext" | |
| fi | |
| echo "Decrypting our file" | |
| java FEA receive receiver_private_key sender_public_key ciphertext our_plaintext && | |
| # comparing decrypted file with original plaintext | |
| if cmp plaintext our_plaintext >/dev/null 2>&1; then | |
| echo " OK!" | |
| else | |
| fail_test "Plaintexts differ" | |
| fi | |
| rm_test_files | |
| } | |
| make || exit 1 | |
| test_genkey | |
| echo | |
| for f in $TEST_DIR/TestVector*; do | |
| echo "Running $(basename $f)" | |
| run_test "$f" | |
| echo | |
| done | |
| test_own_keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment