Lost-Cluster

A small amount of data that does not belong to any file

Matrix code

Base64 encoding is overrated. Encode all your Matrix transmissions in Base138!

Matrix digital rain

Make it rain

<?php
/*
     _______         __         __          ______           __        
    |   |   |.---.-.|  |_.----.|__|.--.--. |      |.-----.--|  |.-----.
    |       ||  _  ||   _|   _||  ||_   _| |   ---||  _  |  _  ||  -__|
    |__|_|__||___._||____|__|  |__||__.__| |______||_____|_____||_____|

    This script is a PHP script that converts a given file into a binary string
    representation using the "Matrix" code. The script takes a file path and an
    optional argument for the type of encoding as input. It first converts the
    contents of the file into an array of integers representing the ASCII code of
    each character. Then, based on the optional argument, it may filter or map the
    array to a different range of values. Next, it converts the array of integers
    to a binary string using the "base_convertion" function, which converts the
    array of integers from the current base (default is 256) to a new base
    (138) using the GMP library. Finally, it outputs the binary string along with a
    hash of the file's contents also in the "Matrix" code format.

    It starts by defining two helper functions: string() which simply casts a given
    input to a string, and base_convertion() which converts a given list of numbers
    from one base to another.

    The to_matrix_code() function is then defined, which takes a list of numbers and
    a base and converts it to a binary representation using the "Matrix" font.

    Then the code reads the contents of a file specified as the first command-line
    argument and converts it into an array of numbers representing the ASCII values
    of each character.

    Then, the code uses a switch statement based on the second command-line argument
    to transform the list of numbers in different ways, such as removing numbers
    that are not within a certain range or mapping them to different values.

    Finally, the code calls to_matrix_code() function to convert the transformed
    list of numbers, the original file's contents, and a hash of the file's
    contents into binary representations using the "Matrix" font, and outputs
    them.

*/


if($argc < 2) die(<<<END
Usage: php {$argv[0]} <file> <source = map>

Types of source:
    ascii   - full 8-bit encoding
    text    - lower 7-bits
    base96  - ascii values: 32 - 127
    range   - all characters between lowest and highest value
    map     - map only used character
END);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome to the matrix</title>
<style>
/* https://github.com/Rezmason/matrix/raw/master/assets/Matrix-Resurrected.ttf */
@font-face { font-family: 'matrix'; src: url('matrix.woff') format('woff'); font-weight: normal; font-style: normal; }
body { font-family: 'matrix'; color: green; background-color: black; margin: 2em; word-wrap: anywhere; writing-mode: vertical-lr; text-orientation: upright; line-height: 1.5em; }
</style>
</head>
<body>
<?php
function base_convertion($list, $from_base, $to_base) {
    $to_length = round(count($list) * log($from_base) / log($to_base));

    $gmp = "0"; $i = 0;
    foreach($list as $value)
        $gmp = gmp_add(gmp_mul(gmp_pow($from_base, $i++), $value), $gmp);

    $list = array();
    for($i = 0; $i < $to_length; $i++) {
        $list[] = gmp_strval(gmp_mod($gmp, $to_base));
        $gmp = gmp_div($gmp, $to_base);
    }

    return($list ?: [0]);
}

function to_matrix_code($list, $base = 256) {
    // https://github.com/Rezmason/matrix
    // in combo with Matrix-Resurrected.ttf
    // https://github.com/Rezmason/matrix/raw/master/assets/Matrix-Resurrected.ttf

    $list = base_convertion($list, $base, 138);
    $bin = implode(array_map(fn($char) => mb_chr(59648 + $char), $list));
    return($bin);
}

$file = file_get_contents($argv[1]);
$list = array_map("ord", str_split($file));

[$list, $base, $map] = [
    "ascii" => function($list) {
        return([$list, 256, false]);
    },
    "text" => function($list) {
        $list = array_filter($list, fn($c) => $c >= 0 && $c < 128);
        return([$list, 128, range(0, 127)]);
    },
    "base96" => function($list) {
        $list = array_map(fn($v) => $v - 32, $list);
        $list = array_filter($list, fn($c) => $c >= 0 && $c < 96);
        return([$list, 96, range(32, 127)]);
    },
    "range" => function($list) {
        $map = array_keys(array_count_values($list));
        sort($map);
        $min = min($map); $max = max($map);
        $list = array_map(fn($v) => $v - $min, $list);
        return([$list, $max - $min + 1, range($min, $max)]);
    },
    "map" => function($list) {
        $map = array_keys(array_count_values($list));
        sort($map);
        $map = array_flip($map);
        $list = array_map(fn($v) => $map[$v], $list);
        return([$list, count($map), array_keys($map)]);
    },
][$argv[2] ?? "map"]($list);

if($map) echo "<p>".to_matrix_code($map)."</p>\n";

$binary = to_matrix_code($list, $base);
echo "<p>".$binary."</p>\n";

$hash = hash("xxh64", $file, true);
$hash = array_map("ord", str_split($hash));
echo "<p>".to_matrix_code($hash)."</p>\n";
?>
</body>
</html>

Example

Digital rain example

Decode

<?php
/*
     _______         __         __          ______           __        
    |   |   |.---.-.|  |_.----.|__|.--.--. |      |.-----.--|  |.-----.
    |       ||  _  ||   _|   _||  ||_   _| |   ---||  _  |  _  ||  -__|
    |__|_|__||___._||____|__|  |__||__.__| |______||_____|_____||_____|

    This script is a PHP script that converts a given file into a binary string
    representation using the "Matrix" code. The script takes a file path and an
    optional argument for the type of encoding as input. It first converts the
    contents of the file into an array of integers representing the ASCII code of
    each character. Then, based on the optional argument, it may filter or map the
    array to a different range of values. Next, it converts the array of integers
    to a binary string using the "base_convertion" function, which converts the
    array of integers from the current base (default is 256) to a new base
    (138) using the GMP library. Finally, it outputs the binary string along with a
    hash of the file's contents also in the "Matrix" code format.

    It starts by defining two helper functions: string() which simply casts a given
    input to a string, and base_convertion() which converts a given list of numbers
    from one base to another.

    The to_matrix_code() function is then defined, which takes a list of numbers and
    a base and converts it to a binary representation using the "Matrix" font.

    Then the code reads the contents of a file specified as the first command-line
    argument and converts it into an array of numbers representing the ASCII values
    of each character.

    Then, the code uses a switch statement based on the second command-line argument
    to transform the list of numbers in different ways, such as removing numbers
    that are not within a certain range or mapping them to different values.

    Finally, the code calls to_matrix_code() function to convert the transformed
    list of numbers, the original file's contents, and a hash of the file's
    contents into binary representations using the "Matrix" font, and outputs
    them.

*/


if($argc < 2) die(<<<END
Usage: php {$argv[0]} <file> <encoding = map>

Types of encoding:
    ascii   - full 8-bit encoding
    text    - lower 7-bits
    base96  - ascii values: 32 - 127
    range   - all characters between lowest and highest value
    map     - map only used character
END);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome to the matrix</title>
<style>
/* https://github.com/Rezmason/matrix/raw/master/assets/Matrix-Resurrected.ttf */
@font-face { font-family: 'matrix'; src: url('matrix.woff') format('woff'); font-weight: normal; font-style: normal; }
body { font-family: 'matrix'; color: green; background-color: black; margin: 2em; word-wrap: anywhere; writing-mode: vertical-lr; text-orientation: upright; line-height: 1.5em; }
</style>
</head>
<body>
<?php
function base_convertion($list, $from_base, $to_base) {
    $to_length = round(count($list) * log($from_base) / log($to_base));

    $gmp = "0"; $i = 0;
    foreach($list as $value)
        $gmp = gmp_add(gmp_mul(gmp_pow($from_base, $i++), $value), $gmp);

    $list = array();
    for($i = 0; $i < $to_length; $i++) {
        $list[] = gmp_strval(gmp_mod($gmp, $to_base));
        $gmp = gmp_div($gmp, $to_base);
    }

    return($list ?: [0]);
}

function to_matrix_code($list, $base = 256) {
    // https://github.com/Rezmason/matrix
    // in combo with Matrix-Resurrected.ttf
    // https://github.com/Rezmason/matrix/raw/master/assets/Matrix-Resurrected.ttf

    $list = base_convertion($list, $base, 138);
    $bin = implode(array_map(fn($char) => mb_chr(59648 + $char), $list));
    return($bin);
}

$file = file_get_contents($argv[1]);
$list = array_map("ord", str_split($file));

[$list, $base, $map] = [
    "ascii" => function($list) {
        return([$list, 256, false]);
    },
    "text" => function($list) {
        $list = array_filter($list, fn($c) => $c >= 0 && $c < 128);
        return([$list, 128, range(0, 127)]);
    },
    "base96" => function($list) {
        $list = array_map(fn($v) => $v - 32, $list);
        $list = array_filter($list, fn($c) => $c >= 0 && $c < 96);
        return([$list, 96, range(32, 127)]);
    },
    "range" => function($list) {
        $map = array_keys(array_count_values($list));
        sort($map);
        $min = min($map); $max = max($map);
        $list = array_map(fn($v) => $v - $min, $list);
        return([$list, $max - $min + 1, range($min, $max)]);
    },
    "map" => function($list) {
        $map = array_keys(array_count_values($list));
        sort($map);
        $map = array_flip($map);
        $list = array_map(fn($v) => $map[$v], $list);
        return([$list, count($map), array_keys($map)]);
    },
][$argv[2] ?? "map"]($list);

if($map) echo "<p>".to_matrix_code($map)."</p>\n";

$binary = to_matrix_code($list, $base);
echo "<p>".$binary."</p>\n";

$hash = hash("xxh64", $file, true);
$hash = array_map("ord", str_split($hash));
echo "<p>".to_matrix_code($hash)."</p>\n";
?>
</body>
</html>

Sources:

matrix (web-based green code rain, made with love)
Matrix Resurrected font
matrix.ttf fontfile (local hosted)
matrix.woff fontfile (local hosted)

The digital rain was a constant reminder of the simulated reality in which humanity was trapped. The code flowed down the towering skyscrapers like a never-ending stream of consciousness, a manifestation of the Matrix's control over every aspect of human existence.