I'm trying to write a shell script that does the viginere cypher with a given text and key and can't figure out how to save the new ascii number for the converted char in a variable. Code down below:
function encode {
local message=$1
local key=$2
local encoded=""
for ((i=0; i<${#message}; i++)); do
local m=`echo $message | cut -c $((i+1))`
local k=`echo $key | cut -c $((i%${#key}+1))`
local m_ascii=`printf "%d" "'$m"`
local k_ascii=`printf "%d" "'$k"`
local e_ascii=$(((m_ascii + k_ascii - 2*97) % 26 + 97))
local e=echo "&e_ascii" | awk '{ printf("%c",$0); }'
encoded="$encoded$e"
done
echo $encoded
}
I also have the same problem in the respective decode function.