Nп/п : 31 из 100
 От   : hongy...@gmail.com                  2:5075/128        03 сен 23 08:27:02
 К    : Ben Bacarisse                                         03 сен 23 18:29:01
 Тема : Re: Split a hex string into bytes and compute the xor of them.
----------------------------------------------------------------------------------
                                                                                 
@MSGID:
<c8087fe1-01a9-488c-a408-d26c00451d9an@googlegroups.com> fef172bb
@REPLY: <878r9nxsav.fsf@bsb.me.uk> e8279370
@REPLYADDR hongy...@gmail.com
<hongyi.zhao@gmail.com>
@REPLYTO 2:5075/128 hongy...@gmail.com
@CHRS: CP866 2
@RFC: 1 0
@RFC-References:
<8404323f-40c3-473b-a5fd-a37e7af1cb3bn@googlegroups.com> <878r9nxsav.fsf@bsb.me.uk>
@RFC-Message-ID:
<c8087fe1-01a9-488c-a408-d26c00451d9an@googlegroups.com>
@TZUTC: -0700
@PID: G2/1.0
@TID: FIDOGATE-5.12-ge4e8b94
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
` $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
` $(($(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
 ", x) }` FPAT=.. <<<
23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 
ea
 werner@X10DAi:~$ gawk `{ x = 0; for (i=1; i<=NF; i++) x =
xor(x,strtonum("0x" $i)); printf "%x
 ", x }` FPAT=.. <<<
23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101 
ea
werner@X10DAi:~$ printf `%x
 ` $(($(sed `s/\\(..\\)/0x\\1^/g` <<<
23230DFE4C5336413245313636504135303333333401000A130A1814300A01010101)0)) 
ea

> -- 
> Ben.

Regards,
Zhao
--- G2/1.0
 * Origin: usenet.network (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



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх