Nп/п : 38 из 100
От : Ben Bacarisse 2:5075/128 06 сен 23 02:31:05
К : Hongy 06 сен 23 04:33:02
Тема : Re: Split a hex string into bytes and compute the xor of them.
----------------------------------------------------------------------------------
@MSGID: <871qfcrsti.fsf@bsb.me.uk> 61c036b9
@REPLY:
<fa93482f-c6a7-454e-88d0-b83e9842a0a2n@googlegroups.com> c4435ac2
@REPLYADDR Ben Bacarisse <ben.usenet@bsb.me.uk>
@REPLYTO 2:5075/128 Ben Bacarisse
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <871qfcrsti.fsf@bsb.me.uk>
<
8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com>
il.me><87jzt6vez1.fsf@bsb.me.uk><c47b672e-ea58-4f16-8de3-405411cf05e4n@googlegroups.co
m><87ledlu66t.fsf@bsb.me.uk>
com>
@TZUTC: 0100
@PID: Gnus/5.13 (Gnus v5.13) Emacs/28.2
(gnu/linux)
@TID: FIDOGATE-5.12-ge4e8b94
"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
` $((${data//??/0x&^}0))
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:"^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
` $((${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
` $((${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.
--- Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
* Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5075/128
@PATH: 5075/128 5020/1042 4441