PageRenderTime 223ms CodeModel.GetById 101ms app.highlight 2ms RepoModel.GetById 118ms app.codeStats 1ms

/system/library/encryption.php

https://bitbucket.org/jjasko/opencart_serbian
PHP | 47 lines | 35 code | 12 blank | 0 comment | 4 complexity | b69920de29322296604622ce582d7a2b MD5 | raw file
 1<?php
 2final class Encryption {
 3	private $key;
 4	
 5	function __construct($key) {
 6        $this->key = $key;
 7	}
 8	
 9	function encrypt($value) {
10		if (!$this->key) { 
11			return $value;
12		}
13		
14		$output = '';
15		
16		for ($i = 0; $i < strlen($value); $i++) {
17			$char = substr($value, $i, 1);
18			$keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1);
19			$char = chr(ord($char) + ord($keychar));
20			
21			$output .= $char;
22		} 
23		
24        return base64_encode($output); 
25	}
26	
27	function decrypt($value) {
28		if (!$this->key) { 
29			return $value;
30		}
31		
32		$output = '';
33		
34		$value = base64_decode($value);
35		
36		for ($i = 0; $i < strlen($value); $i++) {
37			$char = substr($value, $i, 1);
38			$keychar = substr($this->key, ($i % strlen($this->key)) - 1, 1);
39			$char = chr(ord($char) - ord($keychar));
40			
41			$output .= $char;
42		}
43		
44		return $output;
45	}
46}
47?>