Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # cypher v2.4 - encodes & decodes ASCII data
- # Use this key to produce a unique encryption. When decrypting, only the exact same key will give a valid result.
- KEY="1234abcd"
- . whrandom.sh
- ERROR(){
- printf "\033[0;31mError - $1\033[0;32m\n"
- exit 1
- }
- GET_ARRAY(){
- IFS="$(printf '\nx')"
- [ -n "$KEY" ] && for KEY_ARRAY in $(printf "$KEY" | md5sum -b | cut -d" " -f1 | od --endian=big -td1 -An -v -w3 | tr -s " "); do
- SEG=2
- S1=$(($S1+$(printf $KEY_ARRAY | cut -d" " -f$SEG)))
- SEG=$(($SEG+1))
- S2=$(($S2+$(printf $KEY_ARRAY | cut -d" " -f$SEG)))
- SEG=$(($SEG+1))
- S3=$(($S3+$(printf $KEY_ARRAY | cut -d" " -f$SEG)))
- done
- WH_DEL=" "
- ROT_ARRAY=$(WH_RANDOM $S1 $S2 $S3)
- IFS=$DEF_IFS
- }
- [ -z "$1" -o ! -e "$1" ] && ERROR "Wrong input path or file name or none at all.\nUsage: cypher.sh [IN] [OUT] to encode [IN]; cypher.sh [IN] to decode [IN]."
- DEF_IFS=$IFS
- WH_MAX=31
- WH_ALGO=WH_OLD
- if [ -z "$2" ]; then
- WH_LOOP=0
- for NUM in $(tr -s 'A-Zg-z' ' ' < "$1"); do
- if [ -z $S1 ]; then
- S1=$NUM
- elif [ -z $S2 ]; then
- S2=$NUM
- elif [ -z $S3 ]; then
- S3=$NUM
- elif [ $WH_LOOP -eq 0 ]; then
- WH_LOOP=$NUM
- GET_ARRAY
- else
- NUM=$(printf %d 0x$NUM)
- [ $((SEG=$SEG+1)) -gt 1024 ] && SEG=1
- ROT=$(($(printf "$ROT_ARRAY" | cut -d" " -f$SEG)+1))
- printf $(printf '%b' '\\'$(((($NUM << $ROT)/$ROT) >> $ROT)))
- fi
- done
- else
- if [ -e "$2" ]; then
- read -r -p "Output file already exists. Overwrite (y/N)? " OPT
- case $OPT in
- y|Y);;
- *)
- ERROR "Output flile already exists and won't be replaced."
- ;;
- esac
- fi
- S1=$(($(WH_RANDOM)+1))
- S2=$(($(WH_RANDOM)+1))
- S3=$(($(WH_RANDOM)+1))
- [ $((WH_LOOP=$(stat -c '%s' "$1")+3)) -gt 1024 ] && WH_LOOP=1024
- RL=$(gen.sh -fnsc$WH_LOOP -e97-102 -d" ")
- printf $S1$(printf "$RL" | cut -d" " -f1)$S2$(printf "$RL" | cut -d" " -f2)$S3$(printf "$RL" | cut -d" " -f3)$WH_LOOP$(printf "$RL" | cut -d" " -f4) > $2
- GET_ARRAY
- for NUM in $(od --endian=big -to1 -An -v "$1"); do
- [ $((SEG=$SEG+1)) -gt 1024 ] && SEG=1
- ROT=$(($(printf "$ROT_ARRAY" | cut -d" " -f$SEG)+1))
- NUM=$(((((${NUM#${NUM%%[1-9]*}}+0) << $ROT)*$ROT) >> $ROT))
- printf $(printf %x $NUM)$(printf "$RL" | cut -d" " -f$SEG) >> $2
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement