#!/star/Perl/bin/perl
use MIME::Base64;

$baseURL="http://surveys.roe.ac.uk/wsa/";


sub decodeStr { 
$codedStr = $_[0];
$keyinit=$_[1];
$key=$keyinit;
$binCodedStr=decode_base64($codedStr);
$lengthCodedStr= length $binCodedStr;

while (length($key) < $lengthCodedStr) {
  print "\n ",length($key)," ", $lengthCodedStr,"adding \n";
    $key=$key.$keyinit;  
}
$binCodedStr=decode_base64($codedStr);
$lengthCodedStr= length $binCodedStr;
$keybit=substr($key,0,$lengthCodedStr);
$uncodeStr="$binCodedStr"^"$keybit";
return $uncodeStr;
}
sub deMungify { 
$mungedStr = $_[0];
$demungedStr=$mungedStr;
$lengthMStr=length($mungedStr);
$end=$lengthMStr;
$strt=0;
for ($i=0;$i< $lengthMStr; $i++) {
   
    if ($i % 2 == 0){
 	substr($demungedStr,$end-1,1) = substr($mungedStr,$i,1);
	$end=$end-1;
    } else {
         substr($demungedStr,$strt,1) = substr($mungedStr,$i,1);
	$strt=$strt+1;
    }

}
return $demungedStr;
}
1;

