Exemple #1
0
function imageEncrypt($img, $msg)
{
    //set metadata (first line of image)
    //encode length of message
    $msglen = strlen($msg) * 7;
    //number of bits in message
    $msglenBin = toBin("{$msglen}");
    //number of bits represented in binary
    for ($x = 0; $x < strlen($msglenBin); $x++) {
        colorAdjust($img, $x, 0, $msglenBin[$x]);
        //var_dump(imagecolorat($img, $x, 0));
    }
    $msgBin = toBin($msg);
    //message to be sent represented in binary
    $msgIndex = 0;
    for ($y = 1; $y < imagesy($img); $y++) {
        for ($x = 0; $x < imagesx($img); $x++) {
            colorAdjust($img, $x, $y, $msgBin[$msgIndex]);
            $msgIndex++;
            if ($msgIndex >= $msglen) {
                break 2;
            }
        }
    }
    return $img;
}
Exemple #2
0
#!/usr/bin/php
<?php 
/**
 * unpackの使い方
 *
 * 日本語文字列をバイナリダンプする
 * 
 */
$string = "あい";
$bin = toBin($string);
echo $string . "\n";
echo $bin . "\n";
function toBin($str)
{
    $ary = unpack('H*', $str);
    return $ary[1];
}