Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Need help with a custom encrypt function

SpaceshipSpaceship
SpaceshipSpaceship
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.
GoDaddyGoDaddy
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
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back