mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
Update XOREncryption.php
This commit is contained in:
parent
018dfe4920
commit
db6d2b5ec4
@ -1,13 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
function encryptDecrypt($input) {
|
function encryptDecrypt($input) {
|
||||||
$key = ['K', 'C', 'Q']; //Can be any chars, and any size array
|
$key = 'KCQ';
|
||||||
$output = '';
|
$inputLen = strlen($input);
|
||||||
|
$keyLen = strlen($key);
|
||||||
|
|
||||||
for ($i = 0; $i < strlen($input); $i++) {
|
if ($inputLen <= $keyLen) {
|
||||||
$output .= $input[$i] ^ $key[$i % count($key)];
|
return $input ^ $key;
|
||||||
}
|
}
|
||||||
return $output;
|
|
||||||
|
for ($i = 0; $i < $inputLen; ++$i) {
|
||||||
|
$input[$i] = $input[$i] ^ $key[$i % $keyLen];
|
||||||
|
}
|
||||||
|
return $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
$encrypted = encryptDecrypt('kylewbanks.com');
|
$encrypted = encryptDecrypt('kylewbanks.com');
|
||||||
@ -15,4 +20,3 @@ echo "Encrypted:" . $encrypted . "\n";
|
|||||||
|
|
||||||
$decrypted = encryptDecrypt($encrypted);
|
$decrypted = encryptDecrypt($encrypted);
|
||||||
echo "Decrypted:" . $decrypted . "\n";
|
echo "Decrypted:" . $decrypted . "\n";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user