F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\Decoder.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\Decoder.pm
############################################################################### ###############################################################################
# Decoder.pl                                                                  # # Decoder.pm                                                                  #
  # $Date: 01.05.16 $                                                           #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5.2                                                  # # Version:        YaBB 2.6.12                                                 #
# Packaged:       October 21, 2012                                            # # Packaged:       January 5, 2016                                             #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2016 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
############################################################################### ###############################################################################
  our $VERSION = '2.6.12';
   
$decoderplver = 'YaBB 2.5.2 $Revision: 1.0 $'; $decoderpmver = 'YaBB 2.6.12 $Revision: 1710 $';
if ($action eq 'detailedversion') { return 1; } if ( $action eq 'detailedversion' ) { return 1; }
   
sub scramble { sub scramble {
   my ($input, $user) = @_;    my ( $input, $user ) = @_;
   if ($user eq "") { return; }    if ( $user eq q{} ) { return; }
   # creating a codekey based on userid  
   my $carrier = "";     # creating a codekey based on userid 
   for (my $n = 0; $n < length $user; $n++) {     my $carrier = q{}; 
       my $ascii = substr($user, $n, 1);     for my $n ( 0 .. length $user ) { 
       $ascii = ord($ascii);         my $ascii = substr $user, $n, 1; 
       $carrier .= $ascii;        $ascii = ord $ascii;
   }         $carrier .= $ascii; 
   while (length($carrier) < length($input)) { $carrier .= $carrier; }    }
   $carrier = substr($carrier, 0, length($input));     while ( length($carrier) < length $input ) { $carrier .= $carrier; } 
   my $scramble = &encode_password(rand(100));     $carrier = substr $carrier, 0, length $input; 
   for ($n = 0; $n < 10; $n++) {     my $scramble = encode_password( rand 100 ); 
       $scramble .= &encode_password($scramble);     for my $n ( 0 .. 9 ) { 
   }         $scramble .= encode_password($scramble); 
   $scramble =~ s/\//y/g;     } 
   $scramble =~ s/\+/x/g;     $scramble =~ s/\//y/gxsm; 
   $scramble =~ s/\-/Z/g;     $scramble =~ s/\+/x/gxsm; 
   $scramble =~ s/\:/Q/g;     $scramble =~ s/\-/Z/gxsm; 
     $scramble =~ s/\:/Q/gxsm;
   # making a mess of the input  
   my $lastvalue = 3;     # making a mess of the input 
   for (my $n = 0; $n < length $input; $n++) {     my $lastvalue = 3; 
       $value = (substr($carrier, $n, 1)) + $lastvalue + 1;     for my $n ( 0 .. length $input ) { 
       $lastvalue = $value;         $value = ( substr $carrier, $n, 1 ) + $lastvalue + 1; 
       substr($scramble, $value, 1) = substr($input, $n, 1); # does this make sense??? (deti)         $lastvalue = $value; 
   }         substr( $scramble, $value, 1 ) = substr $input, $n, 1; 
     }
   # adding code length to code  
   my $len = length($input) + 65;     # adding code length to code 
   $scramble .= chr($len);     my $len = length($input) + 65; 
   return $scramble;     $scramble .= chr $len; 
     return $scramble;
} }
   
sub descramble { sub descramble {
   my ($input, $user) = @_;    my ( $input, $user ) = @_;
   if ($user eq ""){ return; }    if ( $user eq q{} ) { return; }
   # creating a codekey based on userid  
   my $carrier = "";     # creating a codekey based on userid 
   for (my $n = 0; $n < length($user); $n++) {     my $carrier = q{}; 
       my $ascii = substr($user, $n, 1);     for my $n ( 0 .. ( length($user) - 1 ) ) { 
       $ascii = ord($ascii);         my $ascii = substr $user, $n, 1; 
       $carrier .= $ascii;        $ascii = ord $ascii;
   }         $carrier .= $ascii; 
   my $orgcode   = substr($input, length($input) - 1, 1);     } 
   my $orglength = ord($orgcode);     my $orgcode = substr $input, length($input) - 1, 1; 
     my $orglength = ord $orgcode;
   while (length($carrier) < $orglength - 65) { $carrier .= $carrier; }  
   $carrier = substr($carrier, 0, length($input));     while ( length($carrier) < ( $orglength - 65 ) ) { $carrier .= $carrier; } 
     $carrier = substr $carrier, 0, length $input;
   my $lastvalue  = 3;  
   my $descramble = "";     my $lastvalue  = 3; 
     my $descramble = q{};
   # getting code length from encrypted input  
   for (my $n = 0; $n < $orglength - 65; $n++) {     # getting code length from encrypted input 
       my $value = (substr($carrier, $n, 1)) + $lastvalue + 1;     for my $n ( 0 .. ( $orglength - 66 ) ) { 
       $lastvalue = $value;         my $value = ( substr $carrier, $n, 1 ) + $lastvalue + 1; 
       $descramble .= substr($input, $value, 1);         $lastvalue = $value; 
   }         $descramble .= substr $input, $value, 1; 
   $descramble;     } 
     return $descramble;
} }
   
sub validation_check { sub validation_check {
   my $checkcode = $_[0];     my ($checkcode) = @_; 
   &fatal_error("no_verification_code") if $checkcode eq '';     if ( $checkcode eq q{} ) { fatal_error('no_verification_code'); } 
   &fatal_error("invalid_verification_code") if $checkcode !~ /\A[0-9A-Za-z]+\Z/;     if ( $checkcode !~ /\A[0-9A-Za-z]+\Z/xsm ) { 
   &fatal_error("wrong_verification_code") if &testcaptcha($FORM{"sessionid"}) ne $checkcode;         fatal_error('invalid_verification_code'); 
     }
     if ( testcaptcha( $FORM{'sessionid'} ) ne $checkcode ) {
         fatal_error('wrong_verification_code');
     }
     return;
} }
   
sub validation_code { sub validation_code {
   # set the max length of the shown verification code  
   if (!$codemaxchars || $codemaxchars < 3) { $codemaxchars = 3; }  
   $codemaxchars2 = $codemaxchars + int(rand(2));  
   ## Generate a random string  
   $captcha = &keygen($codemaxchars2,$captchastyle);  
   ## now we are going to spice the captcha with the formsession  
   $sessionid = &scramble ($captcha,$masterkey);  
   chomp $sessionid;  
   
   $showcheck .= qq~<img src="$scripturl?action=$randaction;$randaction=$sessionid" border="0" alt="" /><input type="hidden" name="sessionid" value="$sessionid" />~;     # set the max length of the shown verification code 
   return $sessionid;     my ( $firstCharsLen, $lastCharsLen ); 
     if ($captchaStartChars) { $firstCharsLen = length $captchaStartChars; }
     if ($captchaEndChars)   { $lastCharsLen  = length $captchaEndChars; }
     if ( $captchaStartChars && $captchaEndChars ) {
         $flood_text =
  qq~$floodtxt{'casewarning_1'}$floodtxt{'casewarning_2'} $firstCharsLen $floodtxt{'casewarning_4'} $lastCharsLen $floodtxt{'casewarning_5'}~;
     }
     elsif ($captchaStartChars) {
         $flood_text =
  qq~$floodtxt{'casewarning_1'}$floodtxt{'casewarning_2'} $firstCharsLen $floodtxt{'casewarning_5'}~;
     }
     elsif ($captchaEndChars) {
         $flood_text =
  qq~$floodtxt{'casewarning_1'}$floodtxt{'casewarning_3'} $lastCharsLen $floodtxt{'casewarning_5'}~;
     }
     else {
         $flood_text = qq~$floodtxt{'casewarning'}~;
     }
     if ( !$codemaxchars || $codemaxchars < 3 ) { $codemaxchars = 3; }
     $codemaxchars2 = $codemaxchars + int rand 2;
     ## Generate a random string
     $captcha = keygen( $codemaxchars2, $captchastyle );
     ## now we are going to spice the captcha with the masterkey
     $sessionid = scramble( $captcha, $masterkey );
     chomp $sessionid;
   
     $showcheck .=
  qq~<img src="$scripturl?action=$randaction;$randaction=$sessionid" alt="" /><input type="hidden" name="sessionid" value="$sessionid" />~;
     return $sessionid;
} }
   
sub testcaptcha { sub testcaptcha {
   my $testcode = $_[0];     my ($testcode) = @_; 
   chomp $testcode;    chomp $testcode;
   ## now it is time to decode the session and see if we have a valid code ##    ## now it is time to decode the session and see if we have a valid code ##
   my $out = &descramble($testcode,$masterkey);     my $out = descramble( $testcode, $masterkey ); 
   chomp $out;    chomp $out;
   return $out;    return $out;
} }
   
sub convert { sub convert {
   require "$sourcedir/Captcha.pl";     require Sources::Captcha; 
   $captcha = &testcaptcha($INFO{$randaction});     my ( $startChars, $endChars ); 
   &captcha($captcha);     if ($captchaStartChars) { $startChars = $captchaStartChars; } 
     if ($captchaEndChars)   { $endChars   = $captchaEndChars; }
     $captcha = testcaptcha( $INFO{$randaction} );
     captcha( $startChars . $captcha . $endChars );
     return;
} }
   
1; 1;