Skip to content

Instantly share code, notes, and snippets.

Created February 1, 2013 11:02
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nmcv/4690672 to your computer and use it in GitHub Desktop.
Quick XOR of hexadecimal strings for BASH
# BASH function to get the result
# of a ^ b when a, b are in the
# following hexadecimal string
# form: AF396463D8705 ...
# Obtained from here:
# Author is Sanjay1982 (see
# Usage:
# $ xor AB20FF40 DD14FABC
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[@]} ]
for (( i = 0; i < $count1; i++ ))
res[$i]=$((${one[$i]:-0} ^ ${res[$i]:-0}))
shift 1
printf "%02x" "${res[@]}"
Copy link

Nice work. :)

Copy link

gdb -q -ex 'print/x 0xA ^ 0xF' -ex q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment