Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CalfCrusher/94bde0bd870dee3ab617ed9c8a7c6306 to your computer and use it in GitHub Desktop.
Save CalfCrusher/94bde0bd870dee3ab617ed9c8a7c6306 to your computer and use it in GitHub Desktop.
XOR_string.sh
#!/bin/bash
# Function to XOR a string with a key
xor_string() {
local string=$1
local key=$2
local result=""
for ((i = 0; i < ${#string}; i++)); do
local char=${string:i:1}
local ascii_val=$(printf "%d" "'$char")
local xor_val=$((ascii_val ^ key))
local xor_char=$(printf "\\$(printf '%03o' "$xor_val")")
result+="$xor_char"
done
echo "$result"
}
# Usage example
input_string="HELLO"
xor_key=50
encrypted_string=$(xor_string "$input_string" $xor_key)
echo "Encrypted: $encrypted_string"
decrypted_string=$(xor_string "$encrypted_string" $xor_key)
echo "Decrypted: $decrypted_string"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment