#!/bin/bash
# pgpfake.sh: Fake a pgp/gpg encrypted message with this simple short script.
# It outsmarts the file program (for determing the file type) and human viewers.
# First parameter: Number of (primary) message bytes, Second: Output file name.
# Example: ./pgpfake.sh 1234 important.asc
# Version 1.0, Dr. Rolf Freitag 2009-05-31, License: GPL version 3

# uncomment the next line for debugging
#set -x

# check the number of arguments
if [ $# -ne 2 ] ; then
  echo "Wrong number of paramters (must be 2.: Number, file name)."
  exit -1
fi

typeset -i INPUTBYTECOUNT="$1"
OUTPUTFILE="$2"
TMPFILE="tmpfile"

# make the header
echo "-----BEGIN PGP MESSAGE-----" > "$OUTPUTFILE"
# optional: Charset, Version, Comment etc.
#echo "Charset: ISO-8859-1" >> "$OUTPUTFILE"
#echo "Version: GnuPG v1.4.7 (MingW32)" >> "$OUTPUTFILE"
#echo "Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org" >> "$OUTPUTFILE"
echo "" >> "$OUTPUTFILE"

# make the message (random trash)
#pwgen -s $INPUTBYTECOUNT 1 >> "$TMPFILE"
dd conv=noerror if=/dev/urandom of="$TMPFILE" bs=1 count=$INPUTBYTECOUNT

# Radix-64 = Base64 encoding (RFC 1991, RFC 3548)
base64 -w 64 "$TMPFILE" >> "$OUTPUTFILE"

# make the end
#echo "" >> "$OUTPUTFILE"
echo "-----END PGP MESSAGE-----" >> "$OUTPUTFILE"

# make clean
rm -- "$TMPFILE"

exit 0

