dimanche 25 mars 2018

Fails Decode Message from Image

i have a project to embed message to image with random pixel selected, when i select the pixel with squential method there is no problem, but when i make it random with PRNG, i got different message when i decode it, i think the position when i embed and decode is not different and there is no problem for PRNG code, but why i still got different byte of message, what's wrong with my code, here my embed code:

public byte[] encode_text(byte[] image, byte[] addition, int offset) {
    if (addition.length + offset > image.length) {
        throw new IllegalArgumentException("File tidak cukup di sisipi pesan!");
    }

    String pass= "apam";
    int[] posisi = keygen(pass.toCharArray(), image.length-32);

    for (int i = 0; i < addition.length; ++i) {
        int add = addition[i];
        for (int bit = 7; bit >= 0; --bit) {
            int b = (add >>> bit) & 1;
            image[posisi[i]] = (byte) ((image[posisi[i]+offset] & 0xFE) | b);

        }
    }

    return image;
}

and this is decode :

public byte[] decode_text(byte[] image) {

    int length = 0;
    int offset = 32;
    for (int i = 0; i < 32; ++i) {
        length = (length << 1) | (image[i] & 1);
    }

    byte[] result = new byte[length];

    String pass= "apam";
    int[] posisi = keygen(pass.toCharArray(), image.length-32);

    for (int b = 0; b < result.length; ++b) {
        for (int i = 0; i < 8; ++i) {
            result[b] = (byte) ((result[b] << 1) | (image[posisi[b]+offset] & 1));
        }
    }
    return result;
}




Aucun commentaire:

Enregistrer un commentaire