Created
June 24, 2019 09:53
-
-
Save ninsuo/fe63e35c7e79b5e2246291364c9dea3f to your computer and use it in GitHub Desktop.
Cornichonize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Cornicode | |
{ | |
static public function cornichonize(string $text) { | |
// Reverse | |
$cypher = strrev($text); | |
// Rotate | |
$cypher = str_rot13($cypher); | |
// Hex | |
$cypher = bin2hex($cypher); | |
// Base64 | |
$cypher = base64_encode($cypher); | |
return $cypher; | |
} | |
static public function decornichonize(string $cypher) { | |
// Base64 | |
$cypher = base64_decode($cypher); | |
// Hex | |
$cypher = hex2bin($cypher); | |
// Rotate | |
$cypher = str_rot13($cypher); | |
// Reverse | |
$text = strrev($cypher); | |
return $text; | |
} | |
static public function xorify(string $text, string $key) | |
{ | |
$out = ''; | |
for ($i = 0; $i < strlen($text); ) { | |
for ($j = 0; $j < strlen($key) && $i < strlen($text); $j++, $i++) { | |
$out .= $text[$i] ^ $key[$j]; | |
} | |
} | |
return $out; | |
} | |
} | |
// encode | |
$message = 'The first one to decrypt this wins a tree. Send a :deciduous_tree: emoji to #coding_night'; | |
$key = 'broccoli'; | |
$xorified = base64_encode(Cornicode::xorify($message, $key)); | |
$cornichonized = Cornicode::cornichonize("Ahahah ! C'est beaucoup trop facile, mais qu'est ce que tu croyais ? | |
En fait, le cypher, c'est ça : | |
{$xorified} | |
"); | |
echo $cornichonized, PHP_EOL; | |
// decode | |
$text = Cornicode::decornichonize($cornichonized); | |
echo $text, PHP_EOL; | |
$text = Cornicode::xorify(base64_decode($xorified), $key); | |
echo $text, PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment