Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Disks travel in packs.


devel / comp.unix.shell / Re: Split a hex string into bytes and compute the xor of them.

SubjectAuthor
* Split a hex string into bytes and compute the xor of them.hongy...@gmail.com
+- Split a hex string into bytes and compute the xor of them.marrgol
+- Split a hex string into bytes and compute the xor of them.Kenny McCormack
+* Split a hex string into bytes and compute the xor of them.Ben Bacarisse
|`- Split a hex string into bytes and compute the xor of them.hongy...@gmail.com
`* Split a hex string into bytes and compute the xor of them.Janis Papanagnou
 +* Split a hex string into bytes and compute the xor of them.hongy...@gmail.com
 |`- Split a hex string into bytes and compute the xor of them.Janis Papanagnou
 `* Split a hex string into bytes and compute the xor of them.Ben Bacarisse
  `* Split a hex string into bytes and compute the xor of them.hongy...@gmail.com
   `* Split a hex string into bytes and compute the xor of them.Ben Bacarisse
    `* Split a hex string into bytes and compute the xor of them.hongy...@gmail.com
     `- Split a hex string into bytes and compute the xor of them.Ben Bacarisse

1
Split a hex string into bytes and compute the xor of them.

<8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6599&group=comp.unix.shell#6599

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:8c14:b0:76e:f2b7:dedf with SMTP id qz20-20020a05620a8c1400b0076ef2b7dedfmr133238qkn.12.1693722406026;
Sat, 02 Sep 2023 23:26:46 -0700 (PDT)
X-Received: by 2002:a17:902:e848:b0:1bf:cc5:7b55 with SMTP id
t8-20020a170902e84800b001bf0cc57b55mr2449859plg.0.1693722405341; Sat, 02 Sep
2023 23:26:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sat, 2 Sep 2023 23:26:44 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=208.86.32.27; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 208.86.32.27
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
Subject: Split a hex string into bytes and compute the xor of them.
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 03 Sep 2023 06:26:46 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1468
 by: hongy...@gmail.com - Sun, 3 Sep 2023 06:26 UTC

I want to split a hex string into bytes and compute their xor, as shown below:

werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
ea

I wonder if there is a more concise and simple method for this purpose.

Regards,
Zhao

Re: Split a hex string into bytes and compute the xor of them.

<ud1rq5$t6ap$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6864&group=comp.unix.shell#6864

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: marrgol@address.invalid (marrgol)
Newsgroups: comp.unix.shell
Subject: Re: Split a hex string into bytes and compute the xor of them.
Date: Sun, 3 Sep 2023 13:48:21 +0200
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <ud1rq5$t6ap$1@dont-email.me>
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Sep 2023 11:48:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ecea62f67d434d3ad8f720af692e772f";
logging-data="956761"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UKUdjQfuNr04h9xMNnZAT"
User-Agent: Mozilla/5.0 (rv:102.0) Gecko/20100101, Thunderbird/102.14.0
Cancel-Lock: sha1:LQnxyf8uebOtoqbiH+0Dxt6Scss=
Content-Language: en-GB, pl
In-Reply-To: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
 by: marrgol - Sun, 3 Sep 2023 11:48 UTC

On 2023-09-03 at 08:26 hongy...@gmail.com wrote:
> I want to split a hex string into bytes and compute their xor, as shown below:
>
> werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
> werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
> ea
>
> I wonder if there is a more concise and simple method for this purpose.

E.g.:

DATA=23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101
XOR=0
while read -N2 BYTE; do ((XOR^=0x$BYTE)) ; done < <(echo $DATA)
printf '%02X\n' $XOR

Re: Split a hex string into bytes and compute the xor of them.

<ud21hp$ddll$1@news.xmission.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6865&group=comp.unix.shell#6865

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Split a hex string into bytes and compute the xor of them.
Date: Sun, 3 Sep 2023 13:26:17 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <ud21hp$ddll$1@news.xmission.com>
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
Injection-Date: Sun, 3 Sep 2023 13:26:17 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="439989"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 3 Sep 2023 13:26 UTC

In article <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>,
hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
>I want to split a hex string into bytes and compute their xor, as shown below:
>
>werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<<
>23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e
>'s/[ ]*$//' )
>werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}";
>do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
>ea
>
>I wonder if there is a more concise and simple method for this purpose.

$ gawk '{ x = 0; for (i=1; i<=NF; i++) x = xor(x,strtonum("0x" $i)); print x }' FPAT=.. <<< \
23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101

--
People sleep peaceably in their beds at night only because rough
men stand ready to do violence on their behalf.

George Orwell

Re: Split a hex string into bytes and compute the xor of them.

<878r9nxsav.fsf@bsb.me.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6866&group=comp.unix.shell#6866

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Split a hex string into bytes and compute the xor of them.
Date: Sun, 03 Sep 2023 15:08:56 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <878r9nxsav.fsf@bsb.me.uk>
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4ee5a7923cfe4a48b35c9d5b5ed6532c";
logging-data="1007791"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KEdp2aEvVbWwrDsjcK27JyJ28CGTScnk="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:tzdxzU5AzUD0pPtEtfLOLcSB0Ks=
sha1:tezxfOpzeGSHbWzTd+Cx1YBVevA=
X-BSB-Auth: 1.558d7174afafc290f762.20230903150856BST.878r9nxsav.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 3 Sep 2023 14:08 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:

> I want to split a hex string into bytes and compute their xor, as shown below:
>
> werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
> werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
> ea
>
> I wonder if there is a more concise and simple method for this
> purpose.

You could construct the expression directly. With only two bytes for
clarity:

printf '%x\n' $(($(sed 's/\(..\)/0x\1^/g' <<<2324)0))

The 0 at the end is needed because the sed command adds a trailing ^
operator.

--
Ben.

Re: Split a hex string into bytes and compute the xor of them.

<c8087fe1-01a9-488c-a408-d26c00451d9an@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6867&group=comp.unix.shell#6867

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:3b0a:b0:76d:7b5d:d4c9 with SMTP id tl10-20020a05620a3b0a00b0076d7b5dd4c9mr134191qkn.7.1693754823612;
Sun, 03 Sep 2023 08:27:03 -0700 (PDT)
X-Received: by 2002:a17:90a:e285:b0:268:4dee:eba0 with SMTP id
d5-20020a17090ae28500b002684deeeba0mr1910027pjz.8.1693754823085; Sun, 03 Sep
2023 08:27:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 3 Sep 2023 08:27:02 -0700 (PDT)
In-Reply-To: <878r9nxsav.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=208.86.32.27; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 208.86.32.27
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com> <878r9nxsav.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c8087fe1-01a9-488c-a408-d26c00451d9an@googlegroups.com>
Subject: Re: Split a hex string into bytes and compute the xor of them.
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Sun, 03 Sep 2023 15:27:03 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2798
 by: hongy...@gmail.com - Sun, 3 Sep 2023 15:27 UTC

On Sunday, September 3, 2023 at 10:09:03 PM UTC+8, Ben Bacarisse wrote:
> "hongy...@gmail.com" <hongy...@gmail.com> writes:
>
> > I want to split a hex string into bytes and compute their xor, as shown below:
> >
> > werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
> > werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
> > ea
> >
> > I wonder if there is a more concise and simple method for this
> > purpose.
> You could construct the expression directly. With only two bytes for
> clarity:
>
> printf '%x\n' $(($(sed 's/\(..\)/0x\1^/g' <<<2324)0))
>
> The 0 at the end is needed because the sed command adds a trailing ^
> operator.

Good solution. I have confirmed all the approaches suggested above as follows:

werner@X10DAi:~$ gawk '{ x = 0; for (i=1; i<=NF; i++) x = xor(x,strtonum("0x" $i)); printf("%x\n", x) }' FPAT=.. <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101
ea
werner@X10DAi:~$ gawk '{ x = 0; for (i=1; i<=NF; i++) x = xor(x,strtonum("0x" $i)); printf "%x\n", x }' FPAT=.. <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101
ea
werner@X10DAi:~$ printf '%x\n' $(($(sed 's/\(..\)/0x\1^/g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101)0))
ea

> --
> Ben.

Regards,
Zhao

Re: Split a hex string into bytes and compute the xor of them.

<ud331m$13sv4$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6868&group=comp.unix.shell#6868

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Split a hex string into bytes and compute the xor of them.
Date: Mon, 4 Sep 2023 00:57:57 +0200
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <ud331m$13sv4$1@dont-email.me>
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Sep 2023 22:57:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="037bb60fc6bde642c2f51a160f3e598d";
logging-data="1176548"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18f3CDH+u4r2xqZaKtX1XYh"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:VV6No7843R1JIGp4L+ufo+hPtgU=
In-Reply-To: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sun, 3 Sep 2023 22:57 UTC

On 03.09.2023 08:26, hongy...@gmail.com wrote:
> I want to split a hex string into bytes and compute their xor, as shown below:
>
> werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
> werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
> ea
>
> I wonder if there is a more concise and simple method for this purpose.

You've already got a couple solutions. So just for completeness here's
a Kornshell solution without a shell loop or external commands

data=...
printf "%2x\n" $((${data//@(??)/0x\1^}0))

(functionally it's a variant of Ben's proposal). Unfortunately it seems
that bash (with extglob set) does not support the \1 in the expression?

Janis

> Regards,
> Zhao
>

Re: Split a hex string into bytes and compute the xor of them.

<9e992b6f-44ac-4b58-a1e9-db4d637c3a06n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6869&group=comp.unix.shell#6869

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:11d2:b0:412:2dd3:e0e4 with SMTP id n18-20020a05622a11d200b004122dd3e0e4mr243890qtk.1.1693789214829;
Sun, 03 Sep 2023 18:00:14 -0700 (PDT)
X-Received: by 2002:a05:6a00:1995:b0:68c:6a:aa65 with SMTP id
d21-20020a056a00199500b0068c006aaa65mr3440608pfl.0.1693789214501; Sun, 03 Sep
2023 18:00:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 3 Sep 2023 18:00:13 -0700 (PDT)
In-Reply-To: <ud331m$13sv4$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=208.86.32.27; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 208.86.32.27
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com> <ud331m$13sv4$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9e992b6f-44ac-4b58-a1e9-db4d637c3a06n@googlegroups.com>
Subject: Re: Split a hex string into bytes and compute the xor of them.
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 04 Sep 2023 01:00:14 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2576
 by: hongy...@gmail.com - Mon, 4 Sep 2023 01:00 UTC

On Monday, September 4, 2023 at 6:58:04 AM UTC+8, Janis Papanagnou wrote:
> On 03.09.2023 08:26, hongy...@gmail.com wrote:
> > I want to split a hex string into bytes and compute their xor, as shown below:
> >
> > werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
> > werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
> > ea
> >
> > I wonder if there is a more concise and simple method for this purpose.
> You've already got a couple solutions. So just for completeness here's
> a Kornshell solution without a shell loop or external commands
>
> data=...
> printf "%2x\n" $((${data//@(??)/0x\1^}0))
>
> (functionally it's a variant of Ben's proposal). Unfortunately it seems
> that bash (with extglob set) does not support the \1 in the expression?

What's your ksh version, and which one should I install for testing your code snippet, as listed below?

werner@X10DAi:~$ ksh
Command 'ksh' not found, but can be installed with:
sudo apt install ksh93u+m # version 1.0.0~beta.2-1, or
sudo apt install mksh # version 59c-16
> Janis
>
> > Regards,
> > Zhao
> >

Re: Split a hex string into bytes and compute the xor of them.

<ud3dog$193i3$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6870&group=comp.unix.shell#6870

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Split a hex string into bytes and compute the xor of them.
Date: Mon, 4 Sep 2023 04:00:47 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <ud3dog$193i3$1@dont-email.me>
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
<ud331m$13sv4$1@dont-email.me>
<9e992b6f-44ac-4b58-a1e9-db4d637c3a06n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 4 Sep 2023 02:00:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aff5e3fdd90f8966caf736e70c1692e2";
logging-data="1347139"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pYWdWFeVw/drP1vMigpqR"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:1gmGV8j6bID1m0towZEzVale6T0=
In-Reply-To: <9e992b6f-44ac-4b58-a1e9-db4d637c3a06n@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Mon, 4 Sep 2023 02:00 UTC

On 04.09.2023 03:00, hongy...@gmail.com wrote:
> On Monday, September 4, 2023 at 6:58:04 AM UTC+8, Janis Papanagnou wrote:
>> On 03.09.2023 08:26, hongy...@gmail.com wrote:
>>> I want to split a hex string into bytes and compute their xor, as shown below:
>>>
>>> werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
>>> werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
>>> ea
>>>
>>> I wonder if there is a more concise and simple method for this purpose.
>> You've already got a couple solutions. So just for completeness here's
>> a Kornshell solution without a shell loop or external commands
>>
>> data=...
>> printf "%2x\n" $((${data//@(??)/0x\1^}0))
>>
>> (functionally it's a variant of Ben's proposal). Unfortunately it seems
>> that bash (with extglob set) does not support the \1 in the expression?
>
> What's your ksh version, and which one should I install for testing your code snippet, as listed below?

You should use any of the official or derived versions; this means
ksh93u+ (or ksh93u+m) are fine. (I wouldn't use any clone that has
only incomplete support of origional AT&T Kornshell's features.)

>
> werner@X10DAi:~$ ksh
> Command 'ksh' not found, but can be installed with:
> sudo apt install ksh93u+m # version 1.0.0~beta.2-1, or
> sudo apt install mksh # version 59c-16

Also note, BTW, that all posted solutions might not calculate the
value that you _expect_ in case that the data string has an odd
number of digits; _if_ that can happen with your data you should
take appropriate precautions, e.g. by conditionally prepending a
leading zero in case of an odd number of digits in the data.

Janis

Re: Split a hex string into bytes and compute the xor of them.

<87jzt6vez1.fsf@bsb.me.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6871&group=comp.unix.shell#6871

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Split a hex string into bytes and compute the xor of them.
Date: Mon, 04 Sep 2023 03:39:46 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <87jzt6vez1.fsf@bsb.me.uk>
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
<ud331m$13sv4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="e2cb716c5442438ebe9264e332ee95d9";
logging-data="1351142"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2nWm8Plc4BRitKpJjOHTJ4ju+ISSJeT8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:aZKXDamZ0w5/l1KNpo7P3J9p8iQ=
sha1:RlU92SrLvOv0RbwvzhXMH5avV9s=
X-BSB-Auth: 1.4f6c847da23b195af6fe.20230904033946BST.87jzt6vez1.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 4 Sep 2023 02:39 UTC

Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:

> On 03.09.2023 08:26, hongy...@gmail.com wrote:
>> I want to split a hex string into bytes and compute their xor, as shown below:
>>
>> werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
>> werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
>> ea
>>
>> I wonder if there is a more concise and simple method for this purpose.
>
> You've already got a couple solutions. So just for completeness here's
> a Kornshell solution without a shell loop or external commands
>
> data=...
> printf "%2x\n" $((${data//@(??)/0x\1^}0))

Much neater.

> (functionally it's a variant of Ben's proposal). Unfortunately it seems
> that bash (with extglob set) does not support the \1 in the
> expression?

You can use & but I think it's new:

printf '0x%X\n' $((${data//??/0x&^}0))

and it can be turned on and off via a variable so not idea in something
portable.

--
Ben.

Re: Split a hex string into bytes and compute the xor of them.

<c47b672e-ea58-4f16-8de3-405411cf05e4n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6872&group=comp.unix.shell#6872

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:620a:4c95:b0:76f:27af:2785 with SMTP id to21-20020a05620a4c9500b0076f27af2785mr191049qkn.14.1693801419497;
Sun, 03 Sep 2023 21:23:39 -0700 (PDT)
X-Received: by 2002:a05:6a00:1403:b0:68a:33fc:a094 with SMTP id
l3-20020a056a00140300b0068a33fca094mr3867038pfu.3.1693801419204; Sun, 03 Sep
2023 21:23:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Sun, 3 Sep 2023 21:23:38 -0700 (PDT)
In-Reply-To: <87jzt6vez1.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=208.86.32.27; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 208.86.32.27
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
<ud331m$13sv4$1@dont-email.me> <87jzt6vez1.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c47b672e-ea58-4f16-8de3-405411cf05e4n@googlegroups.com>
Subject: Re: Split a hex string into bytes and compute the xor of them.
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Mon, 04 Sep 2023 04:23:39 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4292
 by: hongy...@gmail.com - Mon, 4 Sep 2023 04:23 UTC

On Monday, September 4, 2023 at 10:39:52 AM UTC+8, Ben Bacarisse wrote:
> Janis Papanagnou <janis_pap...@hotmail.com> writes:
>
> > On 03.09.2023 08:26, hongy...@gmail.com wrote:
> >> I want to split a hex string into bytes and compute their xor, as shown below:
> >>
> >> werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
> >> werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
> >> ea
> >>
> >> I wonder if there is a more concise and simple method for this purpose..
> >
> > You've already got a couple solutions. So just for completeness here's
> > a Kornshell solution without a shell loop or external commands
> >
> > data=...
> > printf "%2x\n" $((${data//@(??)/0x\1^}0))
> Much neater.
> > (functionally it's a variant of Ben's proposal). Unfortunately it seems
> > that bash (with extglob set) does not support the \1 in the
> > expression?
> You can use & but I think it's new:
>
> printf '0x%X\n' $((${data//??/0x&^}0))

I tried to understand the above code snippet with the help of chatgpt-4 as follows:

### begin quote ###
data=...
printf '0x%X\n' $((${data//??/0x&^}0))

explain the above ksh code.

The provided script line is an example of shell arithmetic expansion and parameter substitution in KornShell (ksh).

The code does the following:

1. `data=...`: This defines a variable `data`. It's supposed to have some hex value. The value isn't assigned in your example; it's merely given as ellipsis `...`.

2. `printf '0x%X\n' $((${data//??/0x&^}0))`: This is a more complex part.

- `printf '0x%X\n'`: This is a printf command that prints a number in hexadecimal format ('0x' at the beginning). The `%X` is a format specification for the hexadecimal output.

- `${data//??/0x&^}0`: This is a pattern substitution with arithmetic expansion.

- `${data//??/0x&}`: This will replace every two consecutive characters (`??`) in `data` with `0x&` (where `&` represents the matched part). So, if `data` was `1234`, after this operation it would become `0x120x34`.

- `${data//??/0x&^}0`: The `^` is bitwise XOR in ksh. It's used to XOR all the hexadecimal numbers together. The trailing `0` is necessary as the first XOR operation is between the `0` and the first replaced value.

The whole command is useful in converting multiple byte ASCII values into one big endian hexadecimal value. It opens up the byte string, calculates the XOR of all bytes, and prints out the final value in hexadecimal format.
### end quote ###

But I'm not sure if the above explanation is completely correct.
> and it can be turned on and off via a variable so not idea in something
> portable.
>
> --
> Ben.

Regards,
Zhao

Re: Split a hex string into bytes and compute the xor of them.

<87ledlu66t.fsf@bsb.me.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6873&group=comp.unix.shell#6873

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Split a hex string into bytes and compute the xor of them.
Date: Mon, 04 Sep 2023 19:47:06 +0100
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <87ledlu66t.fsf@bsb.me.uk>
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
<ud331m$13sv4$1@dont-email.me> <87jzt6vez1.fsf@bsb.me.uk>
<c47b672e-ea58-4f16-8de3-405411cf05e4n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="e2cb716c5442438ebe9264e332ee95d9";
logging-data="1667641"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BF35GwBnCjc31rV8ePxBjDi6rZUnhgEQ="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:f7oiZjKsjTVGYi27HyfwH07rzhI=
sha1:O0HKYB+Mc3YG5KG5aOFOD/dtsow=
X-BSB-Auth: 1.8320d1dd8dfea8fad792.20230904194706BST.87ledlu66t.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 4 Sep 2023 18:47 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:

> On Monday, September 4, 2023 at 10:39:52 AM UTC+8, Ben Bacarisse wrote:
>> Janis Papanagnou <janis_pap...@hotmail.com> writes:
>>
>> > On 03.09.2023 08:26, hongy...@gmail.com wrote:
>> >> I want to split a hex string into bytes and compute their xor, as shown below:
>> >>
>> >> werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
>> >> werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
>> >> ea
>> >>
>> >> I wonder if there is a more concise and simple method for this purpose.
>> >
>> > You've already got a couple solutions. So just for completeness here's
>> > a Kornshell solution without a shell loop or external commands
>> >
>> > data=...
>> > printf "%2x\n" $((${data//@(??)/0x\1^}0))
>> Much neater.
>> > (functionally it's a variant of Ben's proposal). Unfortunately it seems
>> > that bash (with extglob set) does not support the \1 in the
>> > expression?

Note that Janis is talking about bash now...

>> You can use & but I think it's new:
>>
>> printf '0x%X\n' $((${data//??/0x&^}0))
>
> I tried to understand the above code snippet with the help of
> chatgpt-4 as follows:
>
> ### begin quote ###
> data=...
> printf '0x%X\n' $((${data//??/0x&^}0))
>
> explain the above ksh code.

It's not ksh code (or not intended to be at last).

> The provided script line is an example of shell arithmetic expansion and parameter substitution in KornShell (ksh).
>
> The code does the following:
>
> 1. `data=...`: This defines a variable `data`. It's supposed to have some hex value. The value isn't assigned in your example; it's merely given as ellipsis `...`.
>
> 2. `printf '0x%X\n' $((${data//??/0x&^}0))`: This is a more complex part.
>
> - `printf '0x%X\n'`: This is a printf command that prints a number in hexadecimal format ('0x' at the beginning). The `%X` is a format specification for the hexadecimal output.
>
> - `${data//??/0x&^}0`: This is a pattern substitution with arithmetic expansion.
>
> - `${data//??/0x&}`: This will replace every two consecutive characters (`??`) in `data` with `0x&` (where `&` represents the matched part). So, if `data` was `1234`, after this operation it would become `0x120x34`.
>
> - `${data//??/0x&^}0`: The `^` is bitwise XOR in ksh. It's used to XOR all the hexadecimal numbers together. The trailing `0` is necessary as the first XOR operation is between the `0` and the first replaced value.
>
> The whole command is useful in converting multiple byte ASCII values into one big endian hexadecimal value. It opens up the byte string, calculates the XOR of all bytes, and prints out the final value in hexadecimal format.
> ### end quote ###
>
> But I'm not sure if the above explanation is completely correct.

Nor me. Why use something like ChatGPT that needs checking? Why not
check it yourself from the bash manual? Or you could ask the group to
explain it if there's some bit you don't follow.

--
Ben.

Re: Split a hex string into bytes and compute the xor of them.

<fa93482f-c6a7-454e-88d0-b83e9842a0a2n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6874&group=comp.unix.shell#6874

  copy link   Newsgroups: comp.unix.shell
X-Received: by 2002:a05:622a:1997:b0:40f:f22c:2a3b with SMTP id u23-20020a05622a199700b0040ff22c2a3bmr445606qtc.3.1693960312019;
Tue, 05 Sep 2023 17:31:52 -0700 (PDT)
X-Received: by 2002:a63:af1a:0:b0:563:e937:5e87 with SMTP id
w26-20020a63af1a000000b00563e9375e87mr3517707pge.5.1693960311730; Tue, 05 Sep
2023 17:31:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell
Date: Tue, 5 Sep 2023 17:31:51 -0700 (PDT)
In-Reply-To: <87ledlu66t.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=208.86.32.27; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 208.86.32.27
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
<ud331m$13sv4$1@dont-email.me> <87jzt6vez1.fsf@bsb.me.uk> <c47b672e-ea58-4f16-8de3-405411cf05e4n@googlegroups.com>
<87ledlu66t.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fa93482f-c6a7-454e-88d0-b83e9842a0a2n@googlegroups.com>
Subject: Re: Split a hex string into bytes and compute the xor of them.
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Wed, 06 Sep 2023 00:31:52 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5607
 by: hongy...@gmail.com - Wed, 6 Sep 2023 00:31 UTC

On Tuesday, September 5, 2023 at 2:47:11 AM UTC+8, Ben Bacarisse wrote:
> "hongy...@gmail.com" <hongy...@gmail.com> writes:
>
> > On Monday, September 4, 2023 at 10:39:52 AM UTC+8, Ben Bacarisse wrote:
> >> Janis Papanagnou <janis_pap...@hotmail.com> writes:
> >>
> >> > On 03.09.2023 08:26, hongy...@gmail.com wrote:
> >> >> I want to split a hex string into bytes and compute their xor, as shown below:
> >> >>
> >> >> werner@X10DAi:~$ data=$( sed 's/\(..\)/\1 /g' <<< 23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 | sed -e 's/[ ]*$//' )
> >> >> werner@X10DAi:~$ IFS=' ' read -ra ADDR <<< "$data"; xor=0; for i in "${ADDR[@]}"; do xor=$((xor ^ 0x$i)); done; printf '%x\n' $xor
> >> >> ea
> >> >>
> >> >> I wonder if there is a more concise and simple method for this purpose.
> >> >
> >> > You've already got a couple solutions. So just for completeness here's
> >> > a Kornshell solution without a shell loop or external commands
> >> >
> >> > data=...
> >> > printf "%2x\n" $((${data//@(??)/0x\1^}0))
> >> Much neater.
> >> > (functionally it's a variant of Ben's proposal). Unfortunately it seems
> >> > that bash (with extglob set) does not support the \1 in the
> >> > expression?
> Note that Janis is talking about bash now...
> >> You can use & but I think it's new:
> >>
> >> printf '0x%X\n' $((${data//??/0x&^}0))
> >
> > I tried to understand the above code snippet with the help of
> > chatgpt-4 as follows:
> >
> > ### begin quote ###
> > data=...
> > printf '0x%X\n' $((${data//??/0x&^}0))
> >
> > explain the above ksh code.
> It's not ksh code (or not intended to be at last).
> > The provided script line is an example of shell arithmetic expansion and parameter substitution in KornShell (ksh).
> >
> > The code does the following:
> >
> > 1. `data=...`: This defines a variable `data`. It's supposed to have some hex value. The value isn't assigned in your example; it's merely given as ellipsis `...`.
> >
> > 2. `printf '0x%X\n' $((${data//??/0x&^}0))`: This is a more complex part.
> >
> > - `printf '0x%X\n'`: This is a printf command that prints a number in hexadecimal format ('0x' at the beginning). The `%X` is a format specification for the hexadecimal output.
> >
> > - `${data//??/0x&^}0`: This is a pattern substitution with arithmetic expansion.
> >
> > - `${data//??/0x&}`: This will replace every two consecutive characters (`??`) in `data` with `0x&` (where `&` represents the matched part). So, if `data` was `1234`, after this operation it would become `0x120x34`.
> >
> > - `${data//??/0x&^}0`: The `^` is bitwise XOR in ksh. It's used to XOR all the hexadecimal numbers together. The trailing `0` is necessary as the first XOR operation is between the `0` and the first replaced value.
> >
> > The whole command is useful in converting multiple byte ASCII values into one big endian hexadecimal value. It opens up the byte string, calculates the XOR of all bytes, and prints out the final value in hexadecimal format.
> > ### end quote ###
> >
> > But I'm not sure if the above explanation is completely correct.
> Nor me. Why use something like ChatGPT that needs checking? Why not
> check it yourself from the bash manual? Or you could ask the group to
> explain it if there's some bit you don't follow.

I tried to test the above code snippet as follows:

werner@X10DAi:~$ echo $SHELL
/bin/bash

werner@X10DAi:~$ data=23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101
werner@X10DAi:~$ printf '0x%X\n' $((${data//??/0x&^}0))
bash: 0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0: syntax error: operand expected (error token is "^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0")
werner@X10DAi:~$ printf '0x%X\n' $((${data//??/0x\1^}0))
0x0
> --
> Ben.

Zhao

Re: Split a hex string into bytes and compute the xor of them.

<871qfcrsti.fsf@bsb.me.uk>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=6875&group=comp.unix.shell#6875

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Split a hex string into bytes and compute the xor of them.
Date: Wed, 06 Sep 2023 02:31:05 +0100
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <871qfcrsti.fsf@bsb.me.uk>
References: <8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
<ud331m$13sv4$1@dont-email.me> <87jzt6vez1.fsf@bsb.me.uk>
<c47b672e-ea58-4f16-8de3-405411cf05e4n@googlegroups.com>
<87ledlu66t.fsf@bsb.me.uk>
<fa93482f-c6a7-454e-88d0-b83e9842a0a2n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="28c87aba986c3fbe6225b4a2a066932e";
logging-data="2366104"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190Cj+zuypELOqgKaeClxWuahWv9hF0Eoo="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:Eur73o8+pnxNdyc2x6mu824B9fI=
sha1:0sGQUnQLSME2jSunhYfG+fk9XZI=
X-BSB-Auth: 1.df3ea8b35e242aa8ad04.20230906023105BST.871qfcrsti.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 6 Sep 2023 01:31 UTC

"hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:

> I tried to test the above code snippet as follows:
>
> werner@X10DAi:~$ echo $SHELL
> /bin/bash
>
> werner@X10DAi:~$ data=23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101
> werner@X10DAi:~$ printf '0x%X\n' $((${data//??/0x&^}0))
> bash: 0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0: syntax error: operand expected (error token is "^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0x&^0")

I wrote:

You can use & but I think it's new:

printf '0x%X\n' $((${data//??/0x&^}0))

and it can be turned on and off via a variable so not ideal in something
portable. (I should have said "via a shell option" and I mis-typed
"ideal".)

man bash says:

If the patsub_replacement shell option is enabled using shopt,
any unquoted instances of & in string are replaced with the
matching portion of pattern.

You may have an old version of bash or you may have patsub_replacement
turned off.

> werner@X10DAi:~$ printf '0x%X\n' $((${data//??/0x\1^}0))

That's not going to work. In bash \1 is just 1 which has no special
meaning in a substitution. Every pair of digits simply gets replaced by
0x1^. The result evaluates to 0 or 1 depending on how many pairs there
are.

--
Ben.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor