Skip to content

Instantly share code, notes, and snippets.

@blizzardengle
Created November 7, 2025 17:48
Show Gist options
  • Select an option

  • Save blizzardengle/14bbc2c6f667fa78d60a359d0de9c28c to your computer and use it in GitHub Desktop.

Select an option

Save blizzardengle/14bbc2c6f667fa78d60a359d0de9c28c to your computer and use it in GitHub Desktop.
PowerShell script to batch password-protect solution ZIP files using weak but compatible encryption as a basic student deterrent.
# Password-protect all ZIP files in current directory
# Password format: BasePassword + first digit found in filename
$basePassword = "PLACEHOLDER"
$sevenZipPath = "C:\Program Files\7-Zip\7z.exe"
# Verify 7-Zip is installed
if (-not (Test-Path $sevenZipPath)) {
Write-Host "ERROR: 7-Zip not found at $sevenZipPath" -ForegroundColor Red
Write-Host "Please install 7-Zip or update the path in the script"
exit
}
# Get all ZIP files in current directory
$zipFiles = Get-ChildItem -Path . -Filter "*.zip"
$totalFiles = $zipFiles.Count
Write-Host "Found $totalFiles ZIP files to process" -ForegroundColor Green
Write-Host ""
$counter = 0
foreach ($zipFile in $zipFiles) {
$counter++
$fileName = $zipFile.Name
# Extract first digit from filename
if ($fileName -match '\d') {
$firstDigit = $matches[0]
} else {
Write-Host "[$counter/$totalFiles] WARNING: No digit found in '$fileName' - SKIPPING" -ForegroundColor Yellow
continue
}
$password = $basePassword + $firstDigit
$tempDir = "temp_extract_$counter"
Write-Host "[$counter/$totalFiles] Processing: $fileName (password ends with: $firstDigit)"
# Extract to temp directory
& $sevenZipPath x "$($zipFile.FullName)" -o"$tempDir" -y | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host " ERROR: Failed to extract $fileName" -ForegroundColor Red
continue
}
# Delete original ZIP
Remove-Item $zipFile.FullName -Force
# Repack with password using ZipCrypto (compatible with all OS)
& $sevenZipPath a -tzip -mem=ZipCrypto -p"$password" "$($zipFile.FullName)" ".\$tempDir\*" | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host " SUCCESS: Repacked with password" -ForegroundColor Green
} else {
Write-Host " ERROR: Failed to repack $fileName" -ForegroundColor Red
}
# Clean up temp directory
Remove-Item $tempDir -Recurse -Force
Write-Host ""
}
Write-Host "Processing complete!" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment