Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Steganography
Sign in to test your solution.
decToChar () {
# converts single-byte decimal value to equivalent character
# arg: decimal number from 0-255
# out: one character
echo -n -e "\x$(printf %02X "$1")"
}
readDecimal() {
# Read the n'th decimal from a file. This function looks at the 2 least significant bits of 4 consecutive bytes in
# the given file and pastes them together to decode the decimal.
# arg1: decimal offset
# arg2: filename from which the given decimal should be read and decoded.
readcharDec () {
# read one character from file & convert to equivalent decimal value
# arg1: offset (# of bytes to skip before reading)
# arg2: filename
# out: decimal value from 0-255
VAL=$(xxd -p -l1 -s $1 $2)
printf %d "0x$VAL"
}
readLSB2 () {
# read the 2 LSB's from the byte at the given position in the given file.
# arg1: byte offset
# arg2: filename
READ_BYTE=$(readcharDec $1 $2)
echo $(( READ_BYTE & 3 ))
}
CURRENT_DECIMAL=0
IDX=$1
FILE=$2
for ((j = 3; j > 0; j--)); do
CURRENT_VAL=$(readLSB2 $(( IDX * 4 + j )) $FILE)
CURRENT_DECIMAL=$(( (CURRENT_DECIMAL | CURRENT_VAL) << 2 ))
done
CURRENT_VAL=$(readLSB2 $(( IDX * 4 )) $FILE)
CURRENT_DECIMAL=$(( (CURRENT_DECIMAL | CURRENT_VAL) ))
echo "$CURRENT_DECIMAL"
}
You can submit as many times as you like. Only your latest submission will be taken into account.
Sign in to test your solution.