我编写了一个操作十六进制值的 bash 脚本,我需要在两个十六进制数之间进行异或运算。我的问题是,当我在 bash 提示符下尝试时,它可以工作并返回正确的值,但在脚本中这个值是假的。
当 XOR 变量 $ExtendAuthKey 和 $IPAD 的结果必须是:181ad673a5d94f0e12c8894ea26381b3636363636363636363636363636363636363636363636363636363636363636363636363636363663636636366
但实际上我得到了这个值:3906369333256140342
我不明白这种行为,如果您有解释或解决方案,我会接受,谢谢
看我的脚本:`
#!/bin/bash
AuthID=80001f8880e9bd0c1d12667a5100000000
IPAD=0x36363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636
OPAD=0x5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c
Ext0=0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
WholeMsgIn=0x3081800201033011020420dd06a7020300ffe30401050201030431302f041180001f8880e9bd0c1d12667a5100000000020105020120040475736572040c00000000000000000000000004003035041180001f8880e9bd0c1d12667a51000000000400a11e02046b4c5ac20201000201003010300e060a2b06010201041e0105010500
line=test
#Calcule AuthKey
AuthKey=$(snmpkey md5 $line $AuthID | grep auth | cut -d ' ' -f 2)
#Concat AuthKey + Ext0
ExtendAuthKey=$AuthKey${Ext0:2}
#Calcule de K1 = ExtendAuthKey XOR IPAD
K1=$(( $ExtendAuthKey ^ $IPAD ))
#Calcule de K2 = ExtendAuthKey XOR OPAD
K2=$(( $ExtendAuthKey ^ $OPAD ))
#Concat K1 + WholeMsgIn
Concat1=$K1$WholeMsgIn
#Calcul Hash Concat1
echo ${Concat1:2} > tempH.hex
cat tempH.hex | xxd -r -p > tempB.bin
HashConcat1=$(md5sum tempB.bin | cut -d ' ' -f 1)
#Concat K2 + Concat1
Concat2=$K2$HashConcat1
#Calcul Hash Concat1
echo ${Concat2:2} > tempH.hex
cat tempH.hex | xxd -r -p > tempB.bin
HashConcat2=$(md5sum tempB.bin | cut -d ' ' -f 1)
`