Skip to content

Instantly share code, notes, and snippets.

@michele-tn
Created January 17, 2026 15:22
Show Gist options
  • Select an option

  • Save michele-tn/d60835f333d00e9172d4705957fd2e8a to your computer and use it in GitHub Desktop.

Select an option

Save michele-tn/d60835f333d00e9172d4705957fd2e8a to your computer and use it in GitHub Desktop.

XZ9-COMPRESSOR

XZ9-COMPRESSOR is a Bash utility designed for maximum compression and cryptographic integrity verification using XZ and SHA-256.


Features

  • Ultra compression using xz -9e
  • Keeps original file intact
  • Automatic SHA-256 checksum generation
  • Secure verification before decompression
  • Interactive menu
  • Lightweight and portable
  • Forensic-grade integrity control

Requirements

  • bash
  • xz-utils
  • coreutils (sha256sum)

On Ubuntu/Debian:

sudo apt install xz-utils coreutils

Usage

Make executable: chmod +x xz9-compressor.sh

Run: ./xz9-compressor.sh

Menu Options

1) Compress file + generate SHA256

  • Compresses file with maximum XZ settings
  • Generates .sha256 checksum file

2) Verify SHA256 and decompress

  • Verifies integrity
  • Only decompresses if hash is valid

3) Exit

Terminates the engine.

Example:

./xz9-compressor.sh
Selection: 1
File to compress: script.sh

Output:

script.sh.xz
script.sh.xz.sha256

Security Model

Decompression is only allowed if:

sha256sum -c file.xz.sha256

Script :

#!/usr/bin/env bash

clear

BANNER="
██╗  ██╗███████╗      █████╗      █████╗ ██████╗  ██████╗
╚██╗██╔╝╚══███╔╝     ██╔══██╗    ██╔══██╗██╔══██╗██╔════╝
 ╚███╔╝   ███╔╝█████╗╚██████║    ███████║██████╔╝██║     
 ██╔██╗  ███╔╝ ╚════╝ ╚═══██║    ██╔══██║██╔══██╗██║     
██╔╝ ██╗███████╗      █████╔╝    ██║  ██║██║  ██║╚██████╗
╚═╝  ╚═╝╚══════╝      ╚════╝     ╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝
                                                         

        XZ9-COMPRESSOR v1.0
   Ultra Compression & Integrity Engine
"

echo -e "\033[1;32m$BANNER\033[0m"

echo "1) Compress file + generate SHA256"
echo "2) Verify SHA256 and decompress"
echo "3) Exit"
echo
read -p "Selection: " CHOICE

echo

if [[ "$CHOICE" == "1" ]]; then

    read -p "File to compress: " FILE

    if [[ ! -f "$FILE" ]]; then
        echo "[-] File not found."
        exit 1
    fi

    echo "[+] XZ9 Ultra Compression Engine active..."
    xz -9e -k "$FILE"

    if [[ $? -ne 0 ]]; then
        echo "[-] Compression error."
        exit 1
    fi

    COMPRESSED="$FILE.xz"

    echo "[+] Generating SHA256 hash..."
    sha256sum "$COMPRESSED" > "$COMPRESSED.sha256"

    echo
    echo "[✓] Operation completed!"
    echo "Archive: $COMPRESSED"
    echo "Hashfile: $COMPRESSED.sha256"

elif [[ "$CHOICE" == "2" ]]; then

    read -p "Compressed file (.xz): " FILE

    if [[ ! -f "$FILE" ]]; then
        echo "[-] File not found."
        exit 1
    fi

    HASHFILE="$FILE.sha256"

    if [[ ! -f "$HASHFILE" ]]; then
        echo "[-] SHA256 file missing."
        exit 1
    fi

    echo "[+] Verifying cryptographic integrity..."
    sha256sum -c "$HASHFILE"

    if [[ $? -ne 0 ]]; then
        echo "[-] HASH INVALID. Access denied."
        exit 1
    fi

    echo "[✓] HASH VERIFIED"
    echo "[+] Decompressing..."

    xz -dk "$FILE"

    if [[ $? -ne 0 ]]; then
        echo "[-] Decompression error."
        exit 1
    fi

    echo "[✓] Decompression completed."

elif [[ "$CHOICE" == "3" ]]; then
    echo "XZ9 Engine terminated."
    exit 0
else
    echo "Invalid command."
fi

echo
echo ">>> XZ9-COMPRESSOR OPERATION COMPLETE <<<"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment