VB icon

dEncryption

Email
Submitted on: 1/1/2015 4:03:00 PM
By: datalogik (from psc cd)  
Level: Intermediate
User Rating: By 10 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 2212
 
     It will encrypt/decrypt a string with the given variables.

 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :dEncryption
//**************************************
Copyright 2003 Jonathan Anders
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: dEncryption
// Description:It will encrypt/decrypt a string with the given variables.
// By: datalogik (from psc cd)
//
// Inputs:	$dString is the string you wish to encrypt
	$dKey is your encryption key
	$dType is to encrypt or decrypt the string ($dType values are 0 or 1,
		0 is encrypt and 1 is decrypt)
	$dIntense is how many times you wish to encrypt the
		string (makes for a more secure and harder to break string)
		Since the highest ascii value for a text character is 255, if
		you set the $dIntense value to 255, it will just loop back to
		where it was, and intern decrypt what you encrypted.
	$dCalcNum is the number that will be added or subtracted with when
		ever encryption begins. The math will take place and will affect
		the first ascii number in the two statements.
//
// Returns:Returns the crypted string.
//
// Side Effects:If the user defines the $dIntense variable to 255, it will not work properly.
//**************************************

<?php
	/*
	Title:
	 dEncryption
	Version:
	 v3
 
	Description:
	 An encryption algorithm with a few twists that I have added.
 
	Author:
	 Jonathan Anders
	 datalogik@datalogik.org
	 http://www.datalogik.org
 
	Usage:
	 function CryptAlg($dString,$dKey,$dType,$dIntense,$dCalcNum)
	 * Where:
	$dString is the string you wish to encrypt
	$dKey is your encryption key
	$dType is to encrypt or decrypt the string ($dType values are 0 or 1,
		0 is encrypt and 1 is decrypt)
	$dIntense is how many times you wish to encrypt the
		string (makes for a more secure and harder to break string)
		Since the highest ascii value for a text character is 255, if
		you set the $dIntense value to 255, it will just loop back to
		where it was, and intern decrypt what you encrypted.
	$dCalcNum is the number that will be added or subtracted with when
		ever encryption begins. The math will take place and will affect
		the first ascii number in the two statements.
	Notes:
	 When crypting a string, remember that you MUST have the exact
	 same $dKey, $dIntense, and $dCalcNum variables as the encrypted
	 or decrypted string for it to accurately do it's job.
	*/
	function CryptAlg($dString,$dKey,$dType,$dIntense,$dCalcNum)
	{
		if ($dIntense > 254)
			$dIntense = 254;
		$dNewString = $dString;
		for ($y = 0; $y <= $dIntense; $y++)
		{
			$strOutput = "";
			$x = 0;
			for ($i = 0; $i < strlen($dNewString); $i++)
			{
				if ($x >= strlen($dKey))
					$x = 0;
				if ($dType == 0)
					$strOutput .= Chr((Ord($dNewString[$i]) + $dCalcNum) - Ord($dKey[$x]));
				if ($dType == 1)
					$strOutput .= Chr((Ord($dNewString[$i]) - $dCalcNum) + Ord($dKey[$x]));
				$x++;
			}
			$dNewString = $strOutput;
		}
		return $dNewString;
	}
	$test = CryptAlg("Crypt Algorithm", "testkey1234567890", 0, 110, 1234567890);
	echo "Encrypted text: $test<br>";
	$test = CryptAlg($test, "testkey1234567890", 1, 110, 1234567890);
	echo "Decrypted text: $test<br>";
?>


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.