#****************************************************************************/
#
# generate_keys
#
# Bash script for key table generation based on /dev/urandom
#
# \author   Michael Skutek
# \date	    19.01.2019
# \version  0.1
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
#***************************************************************************/


#!/bin/bash


read -p "Number of keys (each key is 32 Bit long):" number_keys

echo ""
echo "Don't forget to include <avr/pgmspace.h>!"
echo ""
echo ""

echo "#define NUMBER_OF_SYM_KEYS  $number_keys        //!< specifies the number of keys in this list"
echo ""
echo "const uint32_t sym_key_tab[NUMBER_OF_SYM_KEYS] PROGMEM = {"

for ((i=0; i < number_keys; i++))
 do
     random_number=`od -A n -t x -N 4 /dev/urandom`             # get random numbers
     random_number=`echo $random_number | xargs echo -n`        # remove leading and trailing white spaces
     if [ "$i" = "$(expr $number_keys - 1)" ]; then
        echo "0x$random_number         //!< KEY$i --> to be adapted for each device separately!"
     else
        echo "0x$random_number,        //!< KEY$i --> to be adapted for each device separately!"
     fi
 done

echo "};"
