NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Need help with a custom encrypt function

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-27-2006, 04:31 AM THREAD STARTER               #1 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
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);
????: NamePros.com http://www.namepros.com/programming/231928-need-help-with-custom-encrypt-function.html
        
$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;
        
????: NamePros.com http://www.namepros.com/showthread.php?t=231928
        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 05:12 AM.
Barrucadu is offline  
Old 08-27-2006, 09:13 AM   #2 (permalink)
Senior Member
 
Scott's Avatar
Join Date: Jun 2003
Location: UK
Posts: 3,547
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
 

Member of the Month
February 2005

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
????: NamePros.com http://www.namepros.com/showthread.php?t=231928

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

?>
Scott is offline  
Old 08-27-2006, 11:20 AM THREAD STARTER               #3 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:29 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger