mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
commit
2e36ac5081
@ -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";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user