#!/bin/bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE-$0}")";pwd)
exec 1>>$CUR_DIR"/log/decrypt.log"
exec 2>>$CUR_DIR"/log/decrypt.log.wf"
. ~/.bashrc
function handle_file(){
dir_name=$2
file_name=$3
file_path="/home/work/hdfs_gpdata/alldata/paycoredb/t_tablename/"$dir_name
IFS=""
declare -A mymap
while read line
do
bank_num=`echo -e $line |awk '{print $8}'`
strp="[[:digit:]]{4}[^[:space:]]+.+[=]+[[:digit:]]{4}"
if [[ "$bank_num" =~ $strp ]]
then
if [ ! -n "${mymap[$bank_num]}" ]
then
card_no=`/home/work/php/phppath/bin/php /home/work/daiyuanpei/php_script/decrypt.php ${bank_num}`
mymap[$bank_num]=$card_no
else
card_no=${mymap[$bank_num]}
fi
echo $line | sed "s@${bank_num}@${card_no}@" >> ${file_path}"/"$file_name
else
echo $line >> ${file_path}"/"$file_name
fi
done < $1
#echo ${!mymap[*]}
}
function read_dir(){
for file in `ls $1`
do
if [ -d $1"/"$file ]
then
dir_name=$file
read_dir $1"/"$file
else
handle_file $1"/"$file $2 $file
fi
done
}
read_dir $1 $2
#handle_file $1
<?php
// decrypt.php
require_once("Des.php");
$des = new Pay_Crypt_Des();
$key = '***';
if(isset($argv[1])){
$path = $argv[1];
}else{
echo '';
}
function decrypt_cardno($encrypt_card, $key, $des){
if(is_numeric($encrypt_card) || empty($encrypt_card)){
echo $encrypt_card;
}
if (strpos($encrypt_card, '@') === 0) {
echo $encrypt_card;
}
$decrypt_cardno = $des->decrypt_cardno($encrypt_card,$key,4, 4, true);
echo $decrypt_cardno;
}
decrypt_cardno($argv[1], $key, $des);
?>