Dynadot โ€” .com Transfer

Need help with a custom encrypt function

SpaceshipSpaceship
Watch

Barrucadu

Established Member
Impact
64
Here is my encrypt class:
PHP:
<?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:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
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:
<?php

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

?>
 
0
•••
Ahhhhh, I knew it would be some stupid mistake on my part, thanks.
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy โ€” Zero Commission
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back