Jump to content

Recommended Posts

<?php
//cleanscript.com 
class rot13 {
public $_string = '';
private $string_array = array();
private $alphabet = null;
private $alphabig = null;
private $newstring = '';
public function __construct($string) {
	$this->_string = $string;
	$this->alphabet = range('a','z');
	$this->alphabig = array_map(array(&$this,'alpha_big'),$this->alphabet);
}

public function DeOrEncrypt($crypt = -1) {
	for($x=0;$x<strlen($this->_string);$x++){
		$this->string_array[$x] = $this->_string{$x};
	}
	for($x=0;$x<sizeof($this->string_array);$x++){
		$original = $this->string_array[$x];
		$pos = $this->pos_array(strtolower($this->string_array[$x]));
		if( $pos != -1 ) {
			$ltr = $this->isAlphaBig($original,$pos) ? 1 : -1;
			$newltr = $this->findPos($pos,$ltr,$crypt);
			$this->newstring .= $newltr;
		} else {
			$this->newstring .= $original;
		}
	}
	return $this->newstring;
}

private function alpha_big($x) {
	return strtoupper($x);
}

private function pos_array($letter) {
	for($x=0;$x<sizeof($this->alphabet);$x++) {
		if($this->alphabet[$x] == $letter) {
			return $x;
		}	
	}
	return -1;
}

private function isAlphaBig($char,$pos) {
	if(isset($this->alphabig[$pos])) {
		if($this->alphabig[$pos] == $char) {
			return true;
		} else {
			return false;
		}
	}
	return false;
}

private function findPos($pos,$letter,$crypt) {
	$array = ($letter === -1) ? $this->alphabet : $this->alphabig;
	if( ($crypt == -1 ? $pos + 13 : $pos - 13 ) > sizeof($array) ) {
		$leftover = ($crypt == -1 ? $pos+13 - 26 : $pos-13 + 26);
		return $array[$leftover];
	} else {
		return $array[ ($crypt == -1 ? $pos + 13 : $pos - 13 ) ];
	}
}
}
$rot13 = new rot13("N");
echo $rot13->DeOrEncrypt(1);
?>

 

Have fun, DeOrEncrypt should have a -1 or any other number ;)

 

ROT-13 is Rotate 13. It is an encryption algorithm of sorts. It works like this:

 

Plain text:

This is your protection on Adobe eBooks.

 

Encrypted:

Guvf vf lbhe cebgrpgvba ba Nqbor rObbxf.

 

You rotate the letters in the alphabet 13 positions. 'B' the second letter becomes 'O' the fifteenth letter. Most people use it for fun, not protection.

 

Link to comment
https://forums.phpfreaks.com/topic/113525-my-attempt-on-rot_13-encryption/
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.