Duplicati, Tests, OKD, RISC-V, RDP, B3XOF


#!/usr/bin/env python3

import sys, os, base64

from blake3 import blake3

from argon2.low_level import hash_secret_raw, Type


# Usage: ./script.py [e|d] [password] [text]

mode, pwd, text = sys.argv[1], sys.argv[2].encode(), sys.argv[3]

is_enc = mode.lower().startswith('e')


raw = text.encode() if is_enc else base64.b64decode(text)


# Manage 40-byte metadata blob (16b salt + 24b nonce) and isolate payload data

blob = os.urandom(40) if is_enc else raw[:40]

salt, nonce = blob[:16], blob[16:40]

data = raw if is_enc else raw[40:]


# Key Derivation: Argon2id memory-hard derivation for the 32-byte BLAKE3 key

key = hash_secret_raw(secret=pwd, salt=salt, time_cost=3, memory_cost=65536, parallelism=4, hash_len=32, type=Type.ID)


# Keystream generation: BLAKE3 XOF in keyed mode bound to the nonce

stream = blake3(nonce, key=key).digest(len(data))


# XOR operation. Encrypt prepends metadata blob; Decrypt processes raw data.

out = (int.from_bytes(data) ^ int.from_bytes(stream)).to_bytes(len(data))

res = (blob + out) if is_enc else out


# Output: Base64 for encrypted payloads, raw text for decrypted payloads.

print(base64.b64encode(res).decode() if is_enc else res.decode())

2026-05-17