[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 08-27-2006, 03:31 AM   #1 (permalink)
Barru.
 
Barrucadu's Avatar
 
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,731
78.50 NP$ (Donate)

Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold


Need help with a custom encrypt function

Here is my encrypt class:
PHP Code:
<?php

class Ultimate_Encrypt{

// ------------------------------[ VARIABLES ]------------------------------

    
var $text = '';
    var
$key = 0;
    var
$salt = '';
    var
$salt_bool = false;

// --------------------------[ ENCRYPTION STARTUP ]-------------------------
    
    
function Initialise_Encryption($input, $keycode){
        
$this->text = $input;
        
$this->key = $keycode;
        
        return
true;
    }
    
    function
Initialise_Salt($salt){
        
$this->salt = $salt;
        
$this->salt_bool = true;
        
        return
true;
    }
    
    function
Kill_Salt(){
        
$this->salt = '';
        
$this->salt_bool = false;
        
        return
true;
    }

// -------------------------[ ENCRYPTION FUNCTIONS ]-------------------------

    
function Encrypt(){
        
$iterations = 1;
        
$key = $this->key;
        
$output = $this->text;
        
        
$current = 1;
        
$i = 3;
        
        while(
$current <= $iterations){
            if(
$i == 2){
                if((
$current % 2) and ($key % 2)){
                    
$output = $this->Cypher($output);
                }elseif((
$current % 2)){
                    
$output = $this->Rotate($output);
                }
                
$i = 3;
            }
            
            if(
$i == 3){
                if((
$current % 3) and ($key % 3)){
                    
$output = $this->Punctuation($output);
                }elseif((
$current % 3)){
                    
$output = $this->Reverse($output);
                }
                
$i = 5;
            }
            
            if(
$i == 5){
                if(
$this->salt_bool == true){
                    if((
$current % 5) and ($key % 5)){
                        
$output = $this->Salt2($output);
                    }elseif((
$current % 5)){
                        
$output = $this->Salt1($output);
                    }
                }
                
$i = 2;
            }
        }
        
        return
$output;
    }
    
    function
Cypher($text){
        
$cyphered = str_replace('a','[#]',$text);
        
$cyphered = str_replace('c','[=]',$cyphered);
        
$cyphered = str_replace('e','[+]',$cyphered);
        
$cyphered = str_replace('g','[@]',$cyphered);
        
$cyphered = str_replace('i','[£]',$cyphered);
        
$cyphered = str_replace('k','[:]',$cyphered);
        
$cyphered = str_replace('m','[~]',$cyphered);
        
$cyphered = str_replace('o','[(]',$cyphered);
        
$cyphered = str_replace('q','[)]',$cyphered);
        
$cyphered = str_replace('s','["]',$cyphered);
        
$cyphered = str_replace('u','[?]',$cyphered);
        
$cyphered = str_replace('w','[/]',$cyphered);
        
$cyphered = str_replace('y','[|]',$cyphered);
        
        
$output = str_replace('[','',$cyphered);
        
$output = str_replace(']','',$output);
        
        return
$output;
    }
    
    function
Rotate($text){
        
$i = 0;
        
$output = $text;
        
        while(
$i < strlen($output)){
            
$output[$i] = chr($output[$i]+3);
            
$I++;
        }
        
        return
$output;
    }
    
    function
Punctuation($text){
        
$output = str_replace('a','a ',$text);
        
$output = str_replace('G','G ',$output);
        
$output = str_replace('w','w ',$output);
        
$output = str_replace('L','L ',$output);
        
$output = str_replace('y','y ',$output);
        
$output = str_replace('O','O ',$output);
        
        return
$output;
    }
    
    function
Reverse($text){
        
$output = strrev($text);
        
        return
$output;
    }
    
    function
Salt1($text){
        
$output = $this->salt . $text . $this->salt;
        
        return
$output;
    }
    
    function
Salt2($text){
        
$output = str_replace('A',$this->salt,$text);
        
        return
$output;
    }

}

?>
And here is some code on the same page (below the php for testing):
Code:
Plaintext: hello<br>
Key: 122<br>
Salt: jyf<br><br>
Encrypted Text: <?php
$enc = new Ultimate_Encrypt();
$enc->Initialise_Encryption('hello',122);
$enc->Initialise_Salt('jyf');
echo $enc->Encrypt();
?>
The bug is: when I run the script, the page stays blank for a minute or so, and then spits out an internal server error.

So:
  • Why is it so slow?
  • What causes the 500 error?

Last edited by Mikor; 08-27-2006 at 04:12 AM.
Barrucadu is offline  
Old 08-27-2006, 08:13 AM   #2 (permalink)
Senior Member
 
Scott's Avatar
 
Join Date: Jun 2003
Location: UK
Posts: 3,773
58.82 NP$ (Donate)

Scott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond reputeScott has a reputation beyond repute

Save The Children Save The Children Save The Children Save The Children Save The Children
The script is going into an infinite loop (until the server kills the php process, thus the 500 internal server error) because $iterations == $current.

PHP Code:
<?php

$iterations
= 1;
$current = 1;
while(
$current <= $iterations) {
   
// this keeps looping
}

?>
Scott is offline  
Old 08-27-2006, 10:20 AM   #3 (permalink)
Barru.
 
Barrucadu's Avatar
 
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,731
78.50 NP$ (Donate)

Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold


Ahhhhh, I knew it would be some stupid mistake on my part, thanks.
Barrucadu is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 06:08 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85