Skip to content

Commit

Permalink
XOR Support (#47)
Browse files Browse the repository at this point in the history
* build: add dependency on ext-gmp

* feat: add ability to xor strings

* test: assert xor works

* docs: add "app:xor-string"
  • Loading branch information
iBotPeaches authored Feb 15, 2024
1 parent a50af18 commit 5d2896a
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 217 deletions.
1 change: 1 addition & 0 deletions tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ _Liber Primus decoding._
* `php cicada app:to-runic` - Converts a string to runic.
* `php cicada app:translate` - Translation from runic to English using Gematria values.
* `php cicada app:vigenere` - Decodes a Vigenere cipher using a key and skip indexes from Gematria values.
* `php cicada app:xor-string` - XORs a string with a key.
28 changes: 28 additions & 0 deletions tool/app/Commands/XorString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Commands;

use LaravelZero\Framework\Commands\Command;

class XorString extends Command
{
protected $signature = 'app:xor-string';

protected $description = 'XOR String with a variety of files from previous puzzles.';

public function handle(): int
{
$string = $this->ask('Enter a string to XOR');
$key = $this->ask('Enter the key.');

$xor1 = gmp_init($string, 16);
$xor2 = gmp_init($key, 16);

$xor = gmp_xor($xor1, $xor2);
$output = pack('H*', gmp_strval($xor, 16));

$this->output->write('XOR: '.$output.PHP_EOL);

return self::SUCCESS;
}
}
5 changes: 2 additions & 3 deletions tool/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "MIT",
"require": {
"php": "^8.1",
"ext-gmp": "*",
"drupol/phpermutations": "^1.4",
"laravel-zero/framework": "^10.2",
"league/csv": "^9.0",
Expand All @@ -17,9 +18,7 @@
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
"App\\": "app/"
}
},
"autoload-dev": {
Expand Down
Loading

0 comments on commit 5d2896a

Please sign in to comment.