#!/usr/bin/perl -w use strict; my $text = "Should we turn back for today?\n" . "I wonder if we can go further tomorrow.\n"; # Build set of numeric character codes we want to hash to my %target_chars = (); my $max_char = 0; foreach my $c (unpack 'C*', $text) { $target_chars{$c} = 1; $max_char = $c if $max_char < $c; } # Build set of numeric character codes we want to hash from my %acceptable_chars = (); foreach my $c (33 .. 126) { if( $c != ord('\\') && $c != ord('"') && $c != ord('[') && $c != ord(']') ) { $acceptable_chars{$c} = 1; } } # Search for parameters that would hash from input to target for(my $add = 0; $add < 10; $add++) { for(my $xor = 1; $xor < 100; $xor++) { for(my $mod = $max_char + 1; $mod < 256; $mod++) { my %translation = (); foreach my $from (keys %acceptable_chars) { my $to = ($from + $add ^ $xor) % $mod; next unless exists $target_chars{$to}; $translation{$to} = $from; } if( (scalar keys %translation) == (scalar keys %target_chars) ) { print "output = (input + $add ^ $xor) % $mod\n"; foreach my $c (unpack 'C*', $text) { print chr($translation{$c}); } print "\n"; exit 0; } } } }