src/Pdf/Protection.php
public function rc4($key, $text)
	{
		if ($this->lastRc4Key != $key) {
			$k = str_repeat($key, 256 / strlen($key) + 1);
			$rc4 = range(0, 255);
			$j = 0;
			for ($i = 0; $i < 256; $i++) {
				$t = $rc4[$i];
				$j = ($j + $t + ord($k[$i])) % 256;
				$rc4[$i] = $rc4[$j];
				$rc4[$j] = $t;
			}
			$this->lastRc4Key = $key;
			$this->lastRc4KeyC = $rc4;
		} else {
			$rc4 = $this->lastRc4KeyC;
		}

		$len = strlen($text);
		$a = 0;
		$b = 0;
		$out = '';
		for ($i = 0; $i < $len; $i++) {
			$a = ($a + 1) % 256;
			$t = $rc4[$a];
			$b = ($b + $t) % 256;
			$rc4[$a] = $rc4[$b];
			$rc4[$b] = $t;
			$k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
			$out .= chr(ord($text[$i]) ^ $k);
		}

		return $out;
	}
public function rc4($key, $text)
	{
		if ($this->lastRc4Key != $key) {
			$k = str_repeat($key, 256 / strlen($key) + 1);
			$rc4 = range(0, 255);
			$j = 0;
			for ($i = 0; $i < 256; $i++) {
				$t = $rc4[$i];
				$j = ($j + $t + ord($k[$i])) % 256;
				$rc4[$i] = $rc4[$j];
				$rc4[$j] = $t;
			}
			$this->lastRc4Key = $key;
			$this->lastRc4KeyC = $rc4;
		} else {
			$rc4 = $this->lastRc4KeyC;
		}

		$len = strlen($text);
		$a = 0;
		$b = 0;
		$out = '';
		for ($i = 0; $i < $len; $i++) {
			$a = ($a + 1) % 256;
			$t = $rc4[$a];
			$b = ($b + $t) % 256;
			$rc4[$a] = $rc4[$b];
			$rc4[$b] = $t;
			$k = $rc4[($rc4[$a] + $rc4[$b]) % 256];
			$out .= chr(ord($text[$i]) ^ $k);
		}

		return $out;
	}
public function rc4 ( $ key , $ text ) { if ( $ this -> lastRc4Key != $ key ) { $ k = str_repeat ( $ key , 256 / strlen ( $ key ) + 1 ) ; $ rc4 = range ( 0 , 255 ) ; $ j = 0 ; for ( $ i = 0 ; $ i < 256 ; $ i ++ ) { $ t = $ rc4 [ $ i ] ; $ j = ( $ j + $ t + ord ( $ k [ $ i ] ) ) % 256 ; $ rc4 [ $ i ] = $ rc4 [ $ j ] ; $ rc4 [ $ j ] = $ t ; } $ this -> lastRc4Key = $ key ; $ this -> lastRc4KeyC = $ rc4 ; } else { $ rc4 = $ this -> lastRc4KeyC ; } $ len = strlen ( $ text ) ; $ a = 0 ; $ b = 0 ; $ out = '' ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ a = ( $ a + 1 ) % 256 ; $ t = $ rc4 [ $ a ] ; $ b = ( $ b + $ t ) % 256 ; $ rc4 [ $ a ] = $ rc4 [ $ b ] ; $ rc4 [ $ b ] = $ t ; $ k = $ rc4 [ ( $ rc4 [ $ a ] + $ rc4 [ $ b ] ) % 256 ] ; $ out .= chr ( ord ( $ text [ $ i ] ) ^ $ k ) ; } return $ out ; }
RC4 is the standard encryption algorithm used in PDF format

@param string $key
@param string $text

@return string
RC4 is the standard encryption algorithm used in PDF format