Skip to content

Instantly share code, notes, and snippets.

@Xevion
Created December 6, 2023 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xevion/0dfa6f4c8de471c8cb86485a77f48d63 to your computer and use it in GitHub Desktop.
Save Xevion/0dfa6f4c8de471c8cb86485a77f48d63 to your computer and use it in GitHub Desktop.
# Get a temporary file for storing encrypted outputs
$encryptedFile = New-TemporaryFile
# Milestone testing function
function TestMilestone($milestone, $inputFile, $outputFile, $keyFile, $expectedOutputFile) {
Write-Host "Running Milestone $milestone... " -NoNewline
echo "" # Use echo to skip the system pause
| ./Debug/cs3843-cryptography.exe -e $inputFile -p SECRET -o $outputFile -k $keyFile -m $milestone
| Out-Null # Suppress output
# Compare output files
$encryptOutput = fc.exe /b $outputFile $expectedOutputFile | Out-String
if ($encryptOutput.Contains("no differences")) {
Write-Host "Encrypt Passing, " -NoNewline
} else {
Write-Host "Encrypt Failed, " -NoNewline
}
$decryptedFile = New-TemporaryFile
# Check if decrypt works
echo "" # Use echo to skip the system pause
| ./Debug/cs3843-cryptography.exe -d $outputFile -p SECRET -o $decryptedFile -k $keyFile -m $milestone
| Out-Null # Suppress output
$decryptOutput = fc.exe /b $decryptedFile $inputFile | Out-String
if ($decryptOutput.Contains("no differences")) {
Write-Host "Decrypt Matches"
} else {
Write-Host "Decrypt Failed"
}
}
# Run tests
TestMilestone 1 ATest.txt $encryptedFile Key.dat ATest_milestone1_BADCE.enc
TestMilestone 2 ATest.txt $encryptedFile Key.dat ATest_milestone2_BADCE.enc
TestMilestone 3 ATest.txt $encryptedFile Key.dat ATest_milestone3_BADCE.enc
# Clean up
Remove-Item $encryptedFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment