Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

XECryption algorithm decryptor - Perl Code Bank


XECryption algorithm decryptor
takes encrypted file and outputs the original text. in this encryption algorithm every character turns into .ddd.ddd.ddd where d is digit.
                #!/usr/bin/perl
#XECryption algorithm decryptor
# usage: decrypt.pl encrypted_file
#takes encrypted file and outputs the original text.
#in this encryption algorithm every character turns into .ddd.ddd.ddd where d is digit.


use strict;

main(@ARGV);

sub main{
	my($file_path,$fh,$data,@x,@sum,$space,$password,$asci);
	$file_path = shift;
	open($fh,"<$file_path") or die "Can't open $file_path: $!";
	read($fh,$data,-s $fh);
	close($fh);
	$data=~s/\r\n//g;
	$data=~s/\n//g;
	@x = split('\.',$data);
	shift @x; # dump first one, it's empty!
	while (@x > 0){
		push (@sum,shift(@x) + shift(@x) + shift(@x));
	}
	$space = mostcommon(@sum); # this should be space!
	$password = $space - 32;
	while (@sum > 0){
		$asci = shift(@sum) - $password;
		print chr($asci);
	}
}

sub mostcommon{
	my @nums = @_;
	my(@most_common, %once, %common);
	my $mcc=2; # if there are no common substrings don't store
	
	while( @nums > 0){
	  my $key = shift @nums; #slide down 1 number
	  $common{$key}++;
	  if($common{$key} > $mcc){
	    $mcc=$common{$key};
	    @most_common=($key); #new max set entire array to $key
	  }
	  elsif($common{$key} == $mcc){
	    push(@most_common, $key);  # tack $key onto largest
	  }
	
	  if($common{$key} == 1){
	    $once{$key}=1;
	  }elsif($once{$key}){
	    delete $once{$key};
	  }
	}
	return shift @most_common;
}
            
Comments
Sorry but there are no comments to display