Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <89f2389309ef1efcee726c83b77588c1556e289d@i2pn2.org>
Deutsch   English   Français   Italiano  
<89f2389309ef1efcee726c83b77588c1556e289d@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: Stefan Claas <pollux@tilde.club>
Newsgroups: sci.crypt
Subject: XChaCha20 Python3 CLI tool
Date: Sun, 8 Sep 2024 17:31:34 -0000
Organization: Ch1ffr3punk5
Message-ID: <89f2389309ef1efcee726c83b77588c1556e289d@i2pn2.org>
MIME-Version: 1.0
Injection-Date: Sun, 8 Sep 2024 17:31:57 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="1321608"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="ieSrCjSDShpZNyqIW52mlwIkg76Hsp+TOOO6KTdfCN8";
User-Agent: flnews/1.3.0pre11 (for GNU/Linux)
Cancel-Lock: sha256:vCxbbTE6fHeUviB1GqhEzbslGDGLS3wGYcZfOgl/LAg=
X-Ed25519-Sig: 9c72d1133274c60d5a0a847bd53b355e3ab27f7f8e90daf5aed65685dec56837
 f92a4c9d84a4be5dcb0191f285ad9af85632c97a1a6bb1e2f8a094eea975fb09
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Date: It's Sun 11331 Sep 1993 07:31:34 PM CEST, the September that never ends
X-Ed25519-Pub: c0ffee5a36e581eb10f60b2831b3cdb955d2e7ef680dd282a8d43ad8b84b357a
Bytes: 4972
Lines: 73

Hi all,

DJB's XChaCha20 stream cipher is pretty cool for Text messages (SMS),
if you have also a proper encoder for the binary output.

So I decided to convert my Go Code to Python3.

Here is the program to play with, base64 encoded.

$ ./xchacha20.py
Error: Incorrect number of arguments
Usage: ./xchacha20.py <keyfile> <noncefile> < infile > outfile

XChaCha20 encryption/decryption tool

Arguments:
  keyfile    Path to the file containing the key in hexadecimal format
  noncefile  Path to the file containing the nonce in hexadecimal format

The program reads from stdin and writes to stdout. Use input/output redirection for files.

Examples:
  Encryption: ./xchacha20.py key.hex nonce.hex < plaintext.txt > encrypted.bin
  Decryption: ./xchacha20.py key.hex nonce.hex < encrypted.bin > decrypted.txt

Note: The key should be 32 hex bytes (64 characters) long.
      The nonce should be 24 hex bytes (48 characters) long.

IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwoKaW1wb3J0IHN5cwppbXBvcnQgb3MKZnJvbSBDcnlwdG8u
Q2lwaGVyIGltcG9ydCBDaGFDaGEyMAoKZGVmIHJlYWRfaGV4X2ZpbGUoZmlsZW5hbWUpOgogICAg
d2l0aCBvcGVuKGZpbGVuYW1lLCAncicpIGFzIGY6CiAgICAgICAgaGV4X3N0cmluZyA9IGYucmVh
ZCgpLnN0cmlwKCkKICAgIHJldHVybiBieXRlcy5mcm9taGV4KGhleF9zdHJpbmcpCgpkZWYgcHJp
bnRfdXNhZ2UoKToKICAgIHByaW50KGYiIiJVc2FnZToge3N5cy5hcmd2WzBdfSA8a2V5ZmlsZT4g
PG5vbmNlZmlsZT4gPCBpbmZpbGUgPiBvdXRmaWxlCgpYQ2hhQ2hhMjAgZW5jcnlwdGlvbi9kZWNy
eXB0aW9uIHRvb2wKCkFyZ3VtZW50czoKICBrZXlmaWxlICAgIFBhdGggdG8gdGhlIGZpbGUgY29u
dGFpbmluZyB0aGUga2V5IGluIGhleGFkZWNpbWFsIGZvcm1hdAogIG5vbmNlZmlsZSAgUGF0aCB0
byB0aGUgZmlsZSBjb250YWluaW5nIHRoZSBub25jZSBpbiBoZXhhZGVjaW1hbCBmb3JtYXQKClRo
ZSBwcm9ncmFtIHJlYWRzIGZy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ZSkKICAgIGV4Y2VwdCBFeGNlcHRpb24gYXMgZToKICAgICAgICBw
cmludChmIkVycm9yIHJlYWRpbmcgbm9uY2UgZmlsZToge2V9IiwgZmlsZT1zeXMuc3RkZXJyKQog
ICAgICAgIHN5cy5leGl0KDEpCgogICAgaWYgbGVuKGtleSkgIT0gMzI6CiAgICAgICAgcHJpbnQo
ZiJFcnJvcjogSW52YWxpZCBrZXkgc2l6ZS4gRXhwZWN0ZWQgMzIgaGV4IGJ5dGVzLCBnb3Qge2xl
bihrZXkpfSBieXRlcyIsIGZpbGU9c3lzLnN0ZGVycikKICAgICAgICBzeXMuZXhpdCgxKQoKICAg
IGlmIGxlbihub25jZSkgIT0gMjQ6CiAgICAgICAgcHJpbnQoZiJFcnJvcjogSW52YWxpZCBub25j
ZSBzaXplLiBFeHBlY3RlZCAyNCBoZXggYnl0ZXMsIGdvdCB7bGVuKG5vbmNlKX0gYnl0ZXMiLCBm
aWxlPXN5cy5zdGRlcnIpCiAgICAgICAgc3lzLmV4aXQoMSkKCiAgICBjaXBoZXIgPSBDaGFDaGEy
MC5uZXcoa2V5PWtleSwgbm9uY2U9bm9uY2UpCgogICAgd2hpbGUgVHJ1ZToKICAgICAgICBjaHVu
ayA9IHN5cy5zdGRpbi5idWZmZXIucmVhZCg4MTkyKQogICAgICAgIGlmIG5vdCBjaHVuazoKICAg
ICAgICAgICAgYnJlYWsKICAgICAgICBzeXMuc3Rkb3V0LmJ1ZmZlci53cml0ZShjaXBoZXIuZW5j
cnlwdChjaHVuaykpCgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgbWFpbigpCg==


$ openssl rand -hex 32 > key
$ openssl rand -hex 24 > nonce
$ echo -n 'Hello World!' | xchacha20 key nonce | hexdump -Cv
00000000  01 eb 7f 2e d5 e9 a4 e0  c8 e4 e2 d6 |............|
0000000c

-- 
Regards
Stefan