Translate

Image of Beginning Google Maps API 3
Image of Operating System Concepts
Image of XSLT 2.0 and XPath 2.0 Programmer's Reference (Programmer to Programmer)
Image of Modern Operating Systems (3rd Edition)

Bash XOR A String

Here is an example of how to XOR a string variable using the Bash shell. Each character in the plaintext string is XOR’ed with decimal 90. #!/usr/local/bin/bash plaintext="abcdefg" echo "Plaintext: $plaintext" cyphertext="" for ((i=0; i < ${#plaintext}; i++ )) do ord=$(printf "%d" "’${plaintext:$i:1}") tmp=$(printf \$(printf ‘%03o’ $((ord ^ 90)) )) ciphertext="${ciphertext}${tmp}" done echo "Ciphertext: $ciphertext" # now XOR again and we should get the original string back plaintext="" for ((i=0; i < ${#ciphertext}; i++ )) do ord=$(printf "%d" "’${ciphertext:$i:1}") tmp=$(printf \$(printf ‘%03o’ $((ord ^ 90)) )) plaintext="${plaintext}${tmp}" done echo "Plaintext: $plaintext" The key lines are the ord= and the tmp=