Загрузка данных


$ErrorActionPreference = "Stop"

$dir = Join-Path ([Environment]::GetFolderPath("Desktop")) "LR3"
$source = Join-Path $dir "test.txt"
$archive = Join-Path $dir "12_english.zip"
$temp = Join-Path $dir "12_english_new.zip"
$dictionary = Join-Path $dir "english_custom.dic"
$password = "code"

$sevenZip = @(
    "$env:ProgramFiles\7-Zip\7z.exe",
    "${env:ProgramFiles(x86)}\7-Zip\7z.exe"
) | Where-Object { Test-Path $_ } | Select-Object -First 1

if (-not $sevenZip) { throw "7-Zip not found" }
if (-not (Test-Path $source)) { throw "test.txt not found" }
if (Test-Path $temp) { throw "Temporary archive already exists" }

# Create English dictionary
@(
    "book"
    "data"
    "file"
    "user"
    "safe"
    "lock"
    "test"
    "code"
    "work"
    "time"
    "home"
    "game"
    "word"
    "open"
    "help"
) | Set-Content -Path $dictionary -Encoding ASCII

Write-Host "Dictionary created!" -ForegroundColor Green

# Create new encrypted archive
& $sevenZip a -tzip -mem=AES256 "-p$password" -y $temp $source | Out-Null

if ($LASTEXITCODE -ne 0) {
    throw "Archive creation failed"
}

# Verify password
& $sevenZip t "-p$password" $temp | Out-Null

if ($LASTEXITCODE -ne 0) {
    throw "Archive verification failed"
}

# Back up the original archive
$backupDir = Join-Path $dir "backup"
New-Item -ItemType Directory -Force -Path $backupDir | Out-Null

$backup = Join-Path $backupDir "12_english_original.zip"

if (Test-Path $archive) {
    if (-not (Test-Path $backup)) {
        Move-Item $archive $backup
    } else {
        Remove-Item $archive
    }
}

Move-Item $temp $archive

# Update password table
$csv = Join-Path $dir "passwords.csv"

if (Test-Path $csv) {
    $rows = @(Import-Csv $csv -Delimiter ";")
    foreach ($row in $rows) {
        if ($row.Number -eq "12") {
            $row.Password = $password
        }
    }
    $rows | Export-Csv $csv -Delimiter ";" -NoTypeInformation -Encoding UTF8
}

Write-Host ""
Write-Host "DONE!" -ForegroundColor Green
Write-Host "Archive: $archive"
Write-Host "Password: $password"
Write-Host "Dictionary: $dictionary"