Update XOREncryption.php

This commit is contained in:
woodong 2020-08-17 10:52:27 +08:00 committed by GitHub
parent 018dfe4920
commit db6d2b5ec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,18 @@
<?php
function encryptDecrypt($input) {
$key = ['K', 'C', 'Q']; //Can be any chars, and any size array
$output = '';
$key = 'KCQ';
$inputLen = strlen($input);
$keyLen = strlen($key);
for ($i = 0; $i < strlen($input); $i++) {
$output .= $input[$i] ^ $key[$i % count($key)];
if ($inputLen <= $keyLen) {
return $input ^ $key;
}
return $output;
for ($i = 0; $i < $inputLen; ++$i) {
$input[$i] = $input[$i] ^ $key[$i % $keyLen];
}
return $input;
}
$encrypted = encryptDecrypt('kylewbanks.com');
@ -15,4 +20,3 @@ echo "Encrypted:" . $encrypted . "\n";
$decrypted = encryptDecrypt($encrypted);
echo "Decrypted:" . $decrypted . "\n";