2017-03-01 27 views
0

我有2個文件:1.txt和2.txt,都包含十六進制字符。如何異或2個十六進制輸入?

1.txt : AFCD271E1EF7B1C3 
2.txt : AD6DD9F49F562AF0 

我需要一個命令Linux獲取文件「3.txt」用的1.txt和2.txt的異或兩個數據內容的結果。

例如爲:

3.txt : 2A0FEEA81A19B33 

在此先感謝。

+0

有人做應用程序爲您提供:HTTP:// www.nirsoft.net/utils/xorfiles.html 下一次請更具體地介紹一下編程。你想要的語言或什麼操作系統。 – aslavkin

+0

在此先感謝 –

+0

我更新到這個領域,我需要你的幫助 –

回答

0

創建xorfiles腳本,使用chmod + X xorfiles,xorfiles的1.txt 2.txt> 3.txt

#!/bin/bash 
file1=$(echo| cat $1) 
file2=$(echo | cat $2) 


#xor $file1 $file2 

function xor() 
{ 
     local res=(`echo "$1" | sed "s/../0x& /g"`) 
     shift 1 
     while [[ "$1" ]]; do 
      local one=(`echo "$1" | sed "s/../0x& /g"`) 
      local count1=${#res[@]} 
      if [ $count1 -lt ${#one[@]} ] 
      then 
        count1=${#one[@]} 
      fi 
      for ((i = 0; i < $count1; i++)) 
      do 
        res[$i]=$((${one[$i]:-0}^${res[$i]:-0})) 
      done 
      shift 1 
     done 
     printf "%02x" "${res[@]}" 
} 

echo $(xor $file1 $file2) 

結果:

[email protected]:~$ ./xorfiles ./1.txt ./2.txt 
02a0feea81a19b33