@@ 105-116 (lines=12) @@ | ||
102 | * |
|
103 | * @return string ciphertext |
|
104 | */ |
|
105 | public static function encrypt($uString, $uKey) |
|
106 | { |
|
107 | $tResult = ""; |
|
108 | ||
109 | for ($i = 1, $tCount = strlen($uString); $i <= $tCount; $i++) { |
|
110 | $tChar = substr($uString, $i - 1, 1); |
|
111 | $tKeyChar = substr($uKey, ($i % strlen($uKey)) - 1, 1); |
|
112 | $tResult .= chr(ord($tChar) + ord($tKeyChar)); |
|
113 | } |
|
114 | ||
115 | return $tResult; |
|
116 | } |
|
117 | ||
118 | /** |
|
119 | * Decrypts the ciphertext with the given key |
|
@@ 126-137 (lines=12) @@ | ||
123 | * |
|
124 | * @return string plaintext |
|
125 | */ |
|
126 | public static function decrypt($uString, $uKey) |
|
127 | { |
|
128 | $tResult = ""; |
|
129 | ||
130 | for ($i = 1, $tCount = strlen($uString); $i <= $tCount; $i++) { |
|
131 | $tChar = substr($uString, $i - 1, 1); |
|
132 | $tKeyChar = substr($uKey, ($i % strlen($uKey)) - 1, 1); |
|
133 | $tResult .= chr(ord($tChar) - ord($tKeyChar)); |
|
134 | } |
|
135 | ||
136 | return $tResult; |
|
137 | } |
|
138 | ||
139 | /** |
|
140 | * Reads from a file |