#!/bin/bash

# DeSnowSig - decode a Snow Signature and guess through a list of
#             passphrases to decrypt it
#
# usage: Place the passphrases in a file ~/.snsgpass
#        and either pipe the Snow Signature through this script
#        or give the name of a file with the Snow Signature as a parameter
#
# `snsg' and `gpg' must be installed,
# and the file ~/.temp.snsg is overwritten!
# 
# Copyright (C) 2001 Peter Gerwinski <peter@gerwinski.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#  
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

if [ "$1x" = "x" ]; then
  SNSGFILE=$HOME/.temp.snsg
  rm -f $SNSGFILE
  cat > $SNSGFILE
else
  SNSGFILE=$1
fi
while read -r; do
  if (echo $REPLY; snsg -d $SNSGFILE) \
       | gpg --passphrase-fd 0 --no-tty 2> /dev/null | grep ".*"; then
    echo "[$REPLY]"
  fi
done < $HOME/.snsgpass
