package com.github.serezhka.jap2lib;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

class HandGarbleTest {
    private final HandGarble handGarble = new HandGarble();

    @Test
    void garble1Test() {
        byte[] buffer0 = {-106, 95, -58, 83, -8, 70, -52, 24, -33, -66, -78, -8, 56, -41, -20, 34, 3, -47, 32, -113};
        byte[] buffer1 = {-100, -56, 104, -74, -128, -118, 90, -69, 39, -15, -72, 54, 10, 85, -40, 121, 37, -30, -78, 90, 61, -19, -118, -75, 101, -112, -1, -78, -78, -9, -65, 109, -82, 108, -24, 33, 92, 45, -24, 98, 95, 13, -104, -25, 3, 33, 20, 26, 92, -102, -123, -35, 87, 75, -7, -114, 68, 95, -122, -97, -27, -103, -113, -73, -10, -50, -89, 5, 49, 71, 67, 38, 41, 98, -56, 8, -25, 0, 42, -36, 102, 67, -40, 125, -59, 51, 66, 87, 39, 116, -4, 26, 114, 123, -104, 84, 75, 71, 74, 74, -95, 12, 10, -42, 53, -3, 51, -122, -95, -20, 121, 70, 37, 42, -67, 31, -26, 115, -66, 15, 75, 76, 24, 29, 18, -84, 8, -3, 92, 115, -1, 104, -3, 101, 49, -75, 20, -35, 125, 115, 10, -111, 122, 46, -1, 6, 24, 76, -16, -90, 40, 79, -51, 43, 29, 80, -66, -45, 32, -7, 85, -2, 107, 107, 96, -87, 32, -95, 52, -81, 65, 88, -127, 42, 101, 110, -58, 29, 94, -65, 104, -87, -24, -65, -116, 7, 59, 52, -37, 117, 15, 1, 42, 93, -128, -103, 0, -118, 22, 18, 41, -94, -62, -98, 93, 9, 127, -78, -116, 12};
        byte[] buffer2 = {67, 84, 98, 122, 24, -61, -42, -77, -102, 86, -10, 28, 20, 63, 12, 29, 59, 54, -125, -79, 57, 81, 74, -86, 9, 62, -2, 68, -81, -34, -61, 32, -99, 66, 58};
        byte[] buffer3 = new byte[132];
        byte[] buffer4 = {-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57};

        handGarble.garble(buffer0, buffer1, buffer2, buffer3, buffer4);

        assertArrayEquals(new byte[]{-106, 95, -58, 22, -8, 70, 63, -116, -33, -66, 0, -8, 2, 72, -88, 63, -124, 115, 32, 53},
                buffer0);
        assertArrayEquals(new byte[]{-100, -56, 40, -74, -120, -14, 90, -69, 39, -15, -72, 54, 10, 85, -40, 55, 37, -30, -78, 119, 61, -19, 87, -55, 101, -112, -1, -78, -78, -9, -65, 109, -82, -54, -24, 33, -39, 45, -24, 98, 95, 13, -104, -25, 3, 33, 20, -70, 92, -102, -123, -35, 87, -42, -7, -114, 68, 95, -122, -97, -27, -103, -113, -73, -10, -50, -89, 5, 49, 71, 67, 38, 41, 98, -56, 8, -25, 0, 42, -36, 102, 67, -40, 125, -59, 51, 66, 87, 39, 116, -4, 26, 114, 123, -104, 82, 75, 71, 74, 74, -95, 12, 10, -42, 53, -3, -114, -122, -95, -20, 121, 70, 37, 42, -67, 31, -26, 115, -66, 15, 75, 76, 24, -64, -91, -84, 8, -3, 92, 115, -1, 104, -3, 101, 49, -75, 20, -35, 125, 115, 33, -111, 122, 28, -1, 6, 24, 76, -16, -90, 40, 79, -51, -84, 29, 80, -66, -45, 32, -7, 85, -2, 107, 107, -57, -87, 32, -95, 52, -81, 65, 88, -127, 42, 101, 110, -58, 29, 94, -65, 104, -87, -24, -65, -116, 7, 59, 52, -37, 117, 56, 1, 42, 93, -128, -103, 0, -118, -52, 18, 41, -94, -62, -98, 93, 9, 127, -78, -116, 12},
                buffer1);
        assertArrayEquals(new byte[]{67, 44, -94, 122, 88, 26, -42, -77, -49, 86, -10, 28, 1, -36, -71, 29, 105, 54, -61, -79, 57, 81, -62, -86, 9, -82, -2, 68, 119, -94, 117, 32, -99, -75, -72},
                buffer2);
        assertArrayEquals(new byte[]{-92, 0, 0, 0, -39, 0, 0, 0, 76, 0, 0, 0, -54, 0, 0, 0, -110, 0, 0, 0, 56, 0, 0, 0, 79, 0, 0, 0, -89, 0, 0, 0, -27, 0, 0, 0, -76, 0, 0, 0, 34, 0, 0, 0, 51, 0, 0, 0, 19, 0, 0, 0, 27, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, -52, 0, 0, 0, -34, 0, 0, 0, 10, 0, 0, 0, -92, 0, 0, 0, 8, 0, 0, 0, -44, 0, 0, 0, 68, 0, 0, 0, -96, 0, 0, 0, 46, 0, 0, 0, 27, 0, 0, 0, 119, 0, 0, 0, 0, 0, 0, 0, 51, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, -121, 0, 0, 0, -52, 0, 0, 0},
                buffer3);
        assertArrayEquals(new byte[]{-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57},
                buffer4);
    }

    @Test
    void garble2Test() {
        byte[] buffer0 = {-106, 95, -58, 83, -8, 70, -52, 24, -33, -66, -78, -8, 56, -41, -20, 34, 3, -47, 32, -113};
        byte[] buffer1 = {112, 88, 7, -67, -32, -100, 60, 123, 121, 75, 1, 97, 27, -13, 100, -27, -81, 8, 16, 38, -43, 28, 64, 77, 21, -46, -22, -70, -1, -39, -72, 13, -101, -87, 53, -21, -57, -76, -109, 117, 126, -71, -89, -73, 120, 10, -67, 105, -109, -27, -92, -66, 106, 76, 89, 111, 26, 66, 5, -104, -46, -119, -99, -54, -57, -10, 80, -94, -82, 49, 50, -97, 0, 68, -34, 98, -103, -65, -40, 95, 62, 105, 27, 100, -62, 5, 126, -84, 114, -97, -96, 104, 74, 16, -64, 110, 122, -9, 63, 7, -49, 34, 14, -115, 30, 77, -94, -20, 85, 56, 118, 125, -75, -80, 121, -90, 42, -58, 105, 97, -23, -53, -24, -81, 115, 94, 54, 91, 61, 126, -127, -92, 30, 120, 117, -91, -22, -98, -50, 70, -99, 77, -78, -83, 4, 3, 123, -106, 101, 65, -80, 127, -97, 48, -43, 29, -88, 25, -55, 70, 76, 70, -4, -81, -62, -63, -119, 6, -68, 99, -15, 45, -67, 12, 111, 111, -108, 3, -47, -39, -119, 53, 107, -83, 83, -9, 10, 49, -43, 112, -8, -14, 8, 108, 36, 111, 87, -76, 64, 93, -58, -6, -91, 17, 31, -11, 12, 17, 108, 55};
        byte[] buffer2 = {67, 84, 98, 122, 24, -61, -42, -77, -102, 86, -10, 28, 20, 63, 12, 29, 59, 54, -125, -79, 57, 81, 74, -86, 9, 62, -2, 68, -81, -34, -61, 32, -99, 66, 58};
        byte[] buffer3 = new byte[132];
        byte[] buffer4 = {-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57};

        handGarble.garble(buffer0, buffer1, buffer2, buffer3, buffer4);

        assertArrayEquals(new byte[]{-106, 95, -58, 86, -8, 70, 115, -121, -33, -66, 13, -8, 66, 27, 93, -21, -128, 115, 32, -53},
                buffer0);
        assertArrayEquals(new byte[]{112, 88, -57, -67, 2, 81, 60, 123, 121, 75, 1, 97, 27, -13, 100, 113, -81, 8, 16, 75, -43, 28, 93, 33, 21, -46, -22, -70, -1, -39, -72, 13, -101, -103, 90, -21, 68, -76, -109, 117, 126, -71, -89, -73, 120, 10, -67, -116, -109, -27, -92, -66, 106, -45, 89, 111, 26, 66, 5, -104, -46, -119, -99, -54, -57, -10, 80, -94, -82, 49, 50, -97, 0, 68, -34, 98, -103, -65, -40, 95, 62, 105, 27, 100, -62, 5, 126, -84, 114, -97, -96, 104, 74, 16, -64, -64, 122, -9, 63, 7, -49, 34, 14, -115, 30, 77, 95, -20, 85, 56, 118, 125, -75, -80, 121, -90, 42, -58, 105, 97, -23, -53, -24, 114, -75, 94, 54, 91, 61, 126, -127, -92, 30, 120, 117, -91, -22, -98, -50, 70, 98, 77, -78, 82, 4, 3, 123, -106, 101, 65, -80, 127, -97, -48, -43, 29, -88, 25, -55, 70, 76, 70, -4, -81, -55, -63, -119, 6, -68, 99, -15, 45, -67, 12, 111, 111, -108, 3, -47, -39, -119, 53, 107, -83, 83, -9, 10, 49, -43, 112, 56, -14, 8, 108, 36, 111, 87, -76, -3, 93, -58, -6, -91, 17, 31, -11, 12, 17, 108, 55,},
                buffer1);
        assertArrayEquals(new byte[]{67, 92, 106, 122, 47, -61, -42, -77, 9, 86, -10, 28, 36, -46, -43, 29, 36, 54, 54, -79, 57, 81, -81, -86, 9, 8, -2, 68, 55, -94, -40, 32, -99, -88, -72,},
                buffer2);
        assertArrayEquals(new byte[]{63, 0, 0, 0, 79, 0, 0, 0, 68, 0, 0, 0, -62, 0, 0, 0, 82, 0, 0, 0, 120, 0, 0, 0, 127, 0, 0, 0, 31, 0, 0, 0, 93, 0, 0, 0, 74, 0, 0, 0, 123, 0, 0, 0, 92, 0, 0, 0, 18, 0, 0, 0, 27, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, 69, 0, 0, 0, -72, 0, 0, 0, 8, 0, 0, 0, 11, 0, 0, 0, 28, 0, 0, 0, -72, 0, 0, 0, 111, 0, 0, 0, -33, 0, 0, 0, -83, 0, 0, 0, 27, 0, 0, 0, 54, 0, 0, 0, -126, 0, 0, 0, 9, 0, 0, 0, 96, 0, 0, 0, -17, 0, 0, 0, -75, 0, 0, 0, -10, 0, 0, 0},
                buffer3);
        assertArrayEquals(new byte[]{-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57},
                buffer4);
    }

    @Test
    void garble3Test() {
        byte[] buffer0 = {-106, 95, -58, 83, -8, 70, -52, 24, -33, -66, -78, -8, 56, -41, -20, 34, 3, -47, 32, -113};
        byte[] buffer1 = {-49, -26, -117, -105, 25, -84, -97, 49, 105, 86, 14, -79, -106, -128, -98, 93, 88, 84, -22, 5, -126, -25, -54, 68, -8, 31, 16, 70, 76, 73, -79, -81, 89, 20, -96, -63, -75, -5, 54, 23, 96, 44, -104, -66, 36, -1, -102, -112, 79, -33, -13, 105, -107, -48, 48, -54, 17, -45, 63, -89, 82, 107, -98, 47, -66, -80, 117, -9, -120, 43, 38, 25, 125, -120, -34, -38, -93, 53, 98, 37, -76, -27, 71, -44, -54, -123, 10, 21, -42, -56, -93, -10, 60, 50, -12, 20, 18, 30, 119, 116, -39, -101, -52, 8, 37, 93, 72, 55, 52, 61, -36, -4, -19, -8, 4, 81, 34, -21, -64, -96, 3, 28, -46, 28, -87, -37, -81, 27, 79, -76, -81, 52, -6, 90, 3, -118, -126, -95, 11, -56, 126, 88, -26, -21, 12, 41, -96, 23, -54, 76, -60, -95, 33, -67, -33, -9, -113, -65, -34, -25, 9, -115, -119, -103, 47, 60, 107, -48, -75, -96, 13, 24, 27, 50, 43, -12, -38, -47, 75, -32, -52, 117, 21, 37, 106, -78, -21, 104, 120, 93, 38, -30, -127, 44, 27, -63, -8, -119, 64, 3, 37, 94, 62, 39, 108, 8, 35, 12, 46, 94};
        byte[] buffer2 = {67, 84, 98, 122, 24, -61, -42, -77, -102, 86, -10, 28, 20, 63, 12, 29, 59, 54, -125, -79, 57, 81, 74, -86, 9, 62, -2, 68, -81, -34, -61, 32, -99, 66, 58};
        byte[] buffer3 = new byte[132];
        byte[] buffer4 = {-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57};

        handGarble.garble(buffer0, buffer1, buffer2, buffer3, buffer4);

        assertArrayEquals(new byte[]{-106, 95, -58, 22, -8, 70, -106, -27, -33, -66, 6, -8, 2, 3, -52, -6, 4, 115, 32, -44},
                buffer0);
        assertArrayEquals(new byte[]{-49, -26, 75, -105, 34, -94, -97, 49, 105, 86, 14, -79, -106, -128, -98, -90, 88, 84, -22, 9, -126, -25, 78, -18, -8, 31, 16, 70, 76, 73, -79, -81, 89, 98, -63, -63, 50, -5, 54, 23, 96, 44, -104, -66, 36, -1, -102, 84, 79, -33, -13, 105, -107, -51, 48, -54, 17, -45, 63, -89, 82, 107, -98, 47, -66, -80, 117, -9, -120, 43, 38, 25, 125, -120, -34, -38, -93, 53, 98, 37, -76, -27, 71, -44, -54, -123, 10, 21, -42, -56, -93, -10, 60, 50, -12, -68, 18, 30, 119, 116, -39, -101, -52, 8, 37, 93, -107, 55, 52, 61, -36, -4, -19, -8, 4, 81, 34, -21, -64, -96, 3, 28, -46, -63, -75, -37, -81, 27, 79, -76, -81, 52, -6, 90, 3, -118, -126, -95, 11, -56, 67, 88, -26, -104, 12, 41, -96, 23, -54, 76, -60, -95, 33, 61, -33, -9, -113, -65, -34, -25, 9, -115, -119, -103, 7, 60, 107, -48, -75, -96, 13, 24, 27, 50, 43, -12, -38, -47, 75, -32, -52, 117, 21, 37, 106, -78, -21, 104, 120, 93, 56, -30, -127, 44, 27, -63, -8, -119, -41, 3, 37, 94, 62, 39, 108, 8, 35, 12, 46, 94},
                buffer1);
        assertArrayEquals(new byte[]{67, -84, -128, 122, 12, -88, -42, -77, 26, 86, -10, 28, 28, -124, 62, 29, -22, 54, -123, -79, 57, 81, -127, -86, 9, 108, -2, 68, 55, -94, -99, 32, -99, 74, -72},
                buffer2);
        assertArrayEquals(new byte[]{-85, 0, 0, 0, 72, 0, 0, 0, 76, 0, 0, 0, -15, 0, 0, 0, 114, 0, 0, 0, 88, 0, 0, 0, -95, 0, 0, 0, -1, 0, 0, 0, 61, 0, 0, 0, 84, 0, 0, 0, 38, 0, 0, 0, 110, 0, 0, 0, 2, 0, 0, 0, 27, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, -22, 0, 0, 0, 25, 0, 0, 0, 93, 0, 0, 0, -2, 0, 0, 0, 84, 0, 0, 0, 9, 0, 0, 0, 49, 0, 0, 0, -1, 0, 0, 0, -21, 0, 0, 0, 27, 0, 0, 0, -75, 0, 0, 0, -124, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, -54, 0, 0, 0, 104, 0, 0, 0, -49, 0, 0, 0},
                buffer3);
        assertArrayEquals(new byte[]{-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57},
                buffer4);
    }

    @Test
    void garble4Test() {
        byte[] buffer0 = {-106, 95, -58, 83, -8, 70, -52, 24, -33, -66, -78, -8, 56, -41, -20, 34, 3, -47, 32, -113};
        byte[] buffer1 = {17, -95, 116, 127, -2, 24, 42, -96, -91, 53, -121, 71, -107, 24, 71, 117, -10, 112, 14, -102, 42, -8, 85, 95, -24, 26, 14, 70, -5, 113, 12, -58, -74, -106, -113, 88, -65, 13, -12, 39, -74, 123, -13, 9, 63, -10, 47, -123, -10, -5, -4, -98, 83, 114, -21, 6, 1, -119, 34, -59, -73, -58, 98, -19, 31, -38, 5, 112, 45, 40, -77, -31, 85, 48, 17, 107, -46, 109, 44, 119, 81, 42, 23, -28, 109, -69, 15, -44, -112, -113, -6, -111, 70, -48, 4, -1, 51, -29, 17, 127, -30, 110, 53, -89, -86, 2, -42, -60, -79, 32, -87, -99, -47, -66, -112, 63, 28, -46, -101, -90, -70, 96, -25, 84, 84, 115, -126, 59, -74, 74, 6, -76, 25, 106, 98, -112, 47, 97, -43, -38, -115, -59, -86, -113, -50, -93, 2, -74, 6, 28, -17, -23, -5, -58, -71, -57, -12, -107, -23, -32, 98, -75, -43, 4, -8, -117, -81, -7, -80, -58, -41, 100, 96, -43, 81, -117, -1, 70, 35, -99, -113, 17, 10, 90, -2, 24, 38, -69, 114, 6, -85, -125, 95, 25, -27, -37, -55, 89, -70, 19, 7, -125, 12, -60, -104, 123, -69, -24, -118, -94};
        byte[] buffer2 = {67, 84, 98, 122, 24, -61, -42, -77, -102, 86, -10, 28, 20, 63, 12, 29, 59, 54, -125, -79, 57, 81, 74, -86, 9, 62, -2, 68, -81, -34, -61, 32, -99, 66, 58};
        byte[] buffer3 = new byte[132];
        byte[] buffer4 = {-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57};

        handGarble.garble(buffer0, buffer1, buffer2, buffer3, buffer4);

        assertArrayEquals(new byte[]{-106, 95, -58, 87, -8, 70, -52, -90, -33, -66, 10, -8, 1, 19, 58, -46, 0, 115, 32, -5},
                buffer0);
        assertArrayEquals(new byte[]{17, -95, 52, 127, -30, -4, 42, -96, -91, 53, -121, 71, -107, 24, 71, 23, -10, 112, 14, -102, 42, -8, 71, -13, -24, 26, 14, 70, -5, 113, 12, -58, -74, -58, -108, 88, 60, 13, -12, 39, -74, 123, -13, 9, 63, -10, 47, -125, -10, -5, -4, -98, 83, -45, -21, 6, 1, -119, 34, -59, -73, -58, 98, -19, 31, -38, 5, 112, 45, 40, -77, -31, 85, 48, 17, 107, -46, 109, 44, 119, 81, 42, 23, -28, 109, -69, 15, -44, -112, -113, -6, -111, 70, -48, 4, 2, 51, -29, 17, 127, -30, 110, 53, -89, -86, 2, 79, -60, -79, 32, -87, -99, -47, -66, -112, 63, 28, -46, -101, -90, -70, 96, -25, -119, -27, 115, -126, 59, -74, 74, 6, -76, 25, 106, 98, -112, 47, 97, -43, -38, -115, -59, -86, 121, -50, -93, 2, -74, 6, 28, -17, -23, -5, 77, -71, -57, -12, -107, -23, -32, 98, -75, -43, 4, -116, -117, -81, -7, -80, -58, -41, 100, 96, -43, 81, -117, -1, 70, 35, -99, -113, 17, 10, 90, -2, 24, 38, -69, 114, 6, 56, -125, 95, 25, -27, -37, -55, 89, 57, 19, 7, -125, 12, -60, -104, 123, -69, -24, -118, -94},
                buffer1);
        assertArrayEquals(new byte[]{67, -52, 124, 122, 28, -63, -42, -77, 107, 86, -10, 28, -112, 26, -31, 29, 126, 54, -103, -79, 57, 81, 111, -86, 9, -32, -2, 68, -109, -94, 123, 32, -99, 68, -72},
                buffer2);
        assertArrayEquals(new byte[]{-87, 0, 0, 0, -91, 0, 0, 0, 8, 0, 0, 0, -110, 0, 0, 0, -82, 0, 0, 0, 28, 0, 0, 0, -23, 0, 0, 0, 30, 0, 0, 0, 92, 0, 0, 0, -92, 0, 0, 0, -46, 0, 0, 0, 119, 0, 0, 0, 26, 0, 0, 0, 27, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, -93, 0, 0, 0, -86, 0, 0, 0, 23, 0, 0, 0, 95, 0, 0, 0, -12, 0, 0, 0, -94, 0, 0, 0, -109, 0, 0, 0, -99, 0, 0, 0, -113, 0, 0, 0, 27, 0, 0, 0, 117, 0, 0, 0, 4, 0, 0, 0, 37, 0, 0, 0, 32, 0, 0, 0, -103, 0, 0, 0, -36, 0, 0, 0, 84, 0, 0, 0},
                buffer3);
        assertArrayEquals(new byte[]{-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57},
                buffer4);
    }

    @Test
    void garble5Test() {
        byte[] buffer0 = {-106, 95, -58, 83, -8, 70, -52, 24, -33, -66, -78, -8, 56, -41, -20, 34, 3, -47, 32, -113};
        byte[] buffer1 = {38, 22, -118, -4, 34, -98, -70, 24, -112, 126, 50, -2, -6, 121, -25, 119, 89, -13, -52, 10, 48, 90, -66, 38, -43, -52, 45, 123, -68, 48, 73, -106, 36, 12, 28, 25, 126, -16, 29, -13, -66, -126, -59, 119, 3, 50, 109, -122, 112, 30, 89, -87, -122, -83, 83, 87, -102, -87, 40, -21, -105, 98, 1, -115, 72, 56, 11, 95, -124, 125, -106, 80, -80, 108, -93, -6, 26, 3, -124, -28, 29, 77, -70, -114, 82, -54, -41, 64, 30, -4, 124, -58, 92, -103, -49, 4, 96, 26, -25, 108, 36, 37, -13, 39, 21, -110, -54, -72, 121, 21, 68, 26, -65, 71, -21, 44, -50, 84, -35, 120, 117, 63, -7, -121, 84, 35, -4, -14, -11, 59, 61, -49, 120, 16, -63, -112, 119, -99, 17, -22, -24, 124, -70, 65, -46, 90, 96, -108, 84, -113, 116, -85, -34, 13, 90, -77, -97, -101, 125, -84, -52, -93, 95, 103, -16, -3, 111, -33, 99, -36, -67, 13, 3, -63, -114, 103, 81, -111, -104, -45, 59, 41, -65, -27, -98, 80, -52, -31, 113, 64, 62, 71, 70, 98, -126, 22, 86, 9, -64, 99, -52, 104, -82, -10, -65, 34, 63, -38, 101, -34};
        byte[] buffer2 = {67, 84, 98, 122, 24, -61, -42, -77, -102, 86, -10, 28, 20, 63, 12, 29, 59, 54, -125, -79, 57, 81, 74, -86, 9, 62, -2, 68, -81, -34, -61, 32, -99, 66, 58};
        byte[] buffer3 = new byte[132];
        byte[] buffer4 = {-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57};

        handGarble.garble(buffer0, buffer1, buffer2, buffer3, buffer4);

        assertArrayEquals(new byte[]{-106, 95, -58, 80, -8, 70, -106, -123, -33, -66, 13, -8, -109, 11, 50, 116, -124, 115, 32, -47},
                buffer0);
        assertArrayEquals(new byte[]{38, 22, 74, -4, 114, -15, -70, 24, -112, 126, 50, -2, -6, 121, -25, -71, 89, -13, -52, 15, 48, 90, 85, 14, -43, -52, 45, 123, -68, 48, 73, -106, 36, 40, 69, 25, -5, -16, 29, -13, -66, -126, -59, 119, 3, 50, 109, 57, 112, 30, 89, -87, -122, -42, 83, 87, -102, -87, 40, -21, -105, 98, 1, -115, 72, 56, 11, 95, -124, 125, -106, 80, -80, 108, -93, -6, 26, 3, -124, -28, 29, 77, -70, -114, 82, -54, -41, 64, 30, -4, 124, -58, 92, -103, -49, 82, 96, 26, -25, 108, 36, 37, -13, 39, 21, -110, 119, -72, 121, 21, 68, 26, -65, 71, -21, 44, -50, 84, -35, 120, 117, 63, -7, 90, -75, 35, -4, -14, -11, 59, 61, -49, 120, 16, -63, -112, 119, -99, 17, -22, 89, 124, -70, 42, -46, 90, 96, -108, 84, -113, 116, -85, -34, -19, 90, -77, -97, -101, 125, -84, -52, -93, 95, 103, -8, -3, 111, -33, 99, -36, -67, 13, 3, -63, -114, 103, 81, -111, -104, -45, 59, 41, -65, -27, -98, 80, -52, -31, 113, 64, 56, 71, 70, 98, -126, 22, 86, 9, -68, 99, -52, 104, -82, -10, -65, 34, 63, -38, 101, -34},
                buffer1);
        assertArrayEquals(new byte[]{67, 9, -90, 122, 34, 33, -42, -77, 1, 86, -10, 28, -25, -99, 9, 29, 85, 54, 17, -79, 57, 81, -103, -86, 9, 82, -2, 68, 119, -94, -72, 32, -99, 110, -72},
                buffer2);
        assertArrayEquals(new byte[]{8, 0, 0, 0, -86, 0, 0, 0, 76, 0, 0, 0, -52, 0, 0, 0, -110, 0, 0, 0, 56, 0, 0, 0, -85, 0, 0, 0, -33, 0, 0, 0, 29, 0, 0, 0, 46, 0, 0, 0, 53, 0, 0, 0, 22, 0, 0, 0, 3, 0, 0, 0, 27, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, 77, 0, 0, 0, -77, 0, 0, 0, 0, 0, 0, 0, 103, 0, 0, 0, -128, 0, 0, 0, -79, 0, 0, 0, -100, 0, 0, 0, 72, 0, 0, 0, 65, 0, 0, 0, 27, 0, 0, 0, 114, 0, 0, 0, 10, 0, 0, 0, 3, 0, 0, 0, 96, 0, 0, 0, 66, 0, 0, 0, -77, 0, 0, 0, -120, 0, 0, 0},
                buffer3);
        assertArrayEquals(new byte[]{-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57},
                buffer4);
    }

    @Test
    void garble6Test() {
        byte[] buffer0 = {-106, 95, -58, 83, -8, 70, -52, 24, -33, -66, -78, -8, 56, -41, -20, 34, 3, -47, 32, -113};
        byte[] buffer1 = {34, 126, 12, 15, -113, 98, -9, -105, 124, -15, -87, 97, -96, 44, 109, -75, -28, -113, -95, 17, 75, 110, -29, -73, -56, -78, -98, -62, 31, -54, 5, -3, -28, 42, -41, -12, 65, 20, 116, 121, 1, 27, -25, -119, -103, -72, -14, 113, -38, -66, -118, 17, 22, 80, -77, -125, -97, -128, -54, -55, 87, -66, -88, -79, -72, -19, -64, 65, -104, 114, -127, 14, -65, 28, -106, -91, 103, -102, -104, -21, 68, -125, 79, -55, -36, -59, -6, -96, -7, -108, -13, -72, 95, -6, 34, -84, -51, 69, 68, -28, 122, -49, 59, -17, -120, -59, 69, 113, 3, 122, -18, -25, 22, -34, -86, 100, 69, 39, 113, -115, -42, -82, -67, -103, 57, 22, -91, -86, 82, -82, -86, -40, -111, 32, 110, -102, 48, -95, -53, -83, 36, -86, 79, -9, 116, -64, -34, 102, -29, -5, -44, -103, 44, -113, -53, -96, 44, -19, -60, 86, -80, -29, 99, 84, -67, -128, -47, 125, -46, -98, 26, -25, -2, 82, -18, -42, 62, -106, 13, 73, -14, 25, -41, 63, -78, 69, -34, -116, 20, -116, -63, -57, 37, 74, 33, 9, 61, -101, 49, 113, 59, 85, 47, -76, -2, 4, -112, -103, 24, -27};
        byte[] buffer2 = {67, 84, 98, 122, 24, -61, -42, -77, -102, 86, -10, 28, 20, 63, 12, 29, 59, 54, -125, -79, 57, 81, 74, -86, 9, 62, -2, 68, -81, -34, -61, 32, -99, 66, 58};
        byte[] buffer3 = new byte[132];
        byte[] buffer4 = {-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57};

        handGarble.garble(buffer0, buffer1, buffer2, buffer3, buffer4);

        assertArrayEquals(new byte[]{-106, 95, -58, -70, -8, 70, 95, 107, -33, -66, 12, -8, 65, 31, 93, 115, 0, 115, 32, -116},
                buffer0);
        assertArrayEquals(new byte[]{34, 126, -52, 15, -46, 0, -9, -105, 124, -15, -87, 97, -96, 44, 109, 75, -28, -113, -95, 54, 75, 110, 92, 123, -56, -78, -98, -62, 31, -54, 5, -3, -28, 90, -41, -12, -66, 20, 116, 121, 1, 27, -25, -119, -103, -72, -14, -115, -38, -66, -118, 17, 22, -45, -77, -125, -97, -128, -54, -55, 87, -66, -88, -79, -72, -19, -64, 65, -104, 114, -127, 14, -65, 28, -106, -91, 103, -102, -104, -21, 68, -125, 79, -55, -36, -59, -6, -96, -7, -108, -13, -72, 95, -6, 34, 82, -51, 69, 68, -28, 122, -49, 59, -17, -120, -59, -8, 113, 3, 122, -18, -25, 22, -34, -86, 100, 69, 39, 113, -115, -42, -82, -67, 68, -67, 22, -91, -86, 82, -82, -86, -40, -111, 32, 110, -102, 48, -95, -53, -83, 59, -86, 79, -96, 116, -64, -34, 102, -29, -5, -44, -103, 44, -58, -53, -96, 44, -19, -60, 86, -80, -29, 99, 84, -11, -128, -47, 125, -46, -98, 26, -25, -2, 82, -18, -42, 62, -106, 13, 73, -14, 25, -41, 63, -78, 69, -34, -116, 20, -116, 56, -57, 37, 74, 33, 9, 61, -101, 64, 113, 59, 85, 47, -76, -2, 4, -112, -103, 24, -27},
                buffer1);
        assertArrayEquals(new byte[]{67, 60, 100, 122, 23, -61, -42, -77, -92, 86, -10, 28, 47, 61, -68, 29, -19, 54, -58, -79, 57, 81, -99, -86, 9, 94, -2, 68, 119, -94, -113, 32, -99, -44, -72},
                buffer2);
        assertArrayEquals(new byte[]{-39, 0, 0, 0, 116, 0, 0, 0, 76, 0, 0, 0, 54, 0, 0, 0, -110, 0, 0, 0, 56, 0, 0, 0, -103, 0, 0, 0, -82, 0, 0, 0, -20, 0, 0, 0, -78, 0, 0, 0, 72, 0, 0, 0, -42, 0, 0, 0, 24, 0, 0, 0, 27, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, -37, 0, 0, 0, -60, 0, 0, 0, 30, 0, 0, 0, -78, 0, 0, 0, -47, 0, 0, 0, 0, 0, 0, 0, -20, 0, 0, 0, -9, 0, 0, 0, 27, 0, 0, 0, 115, 0, 0, 0, 8, 0, 0, 0, 112, 0, 0, 0, 2, 0, 0, 0, -44, 0, 0, 0, -113, 0, 0, 0, -26, 0, 0, 0},
                buffer3);
        assertArrayEquals(new byte[]{-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57},
                buffer4);
    }

    @Test
    void garble7Test() {
        byte[] buffer0 = {-106, 95, -58, 83, -8, 70, -52, 24, -33, -66, -78, -8, 56, -41, -20, 34, 3, -47, 32, -113};
        byte[] buffer1 = {27, 49, -36, -43, 67, -103, -123, 83, -104, 73, 51, -76, -40, -1, -16, 34, 8, -96, 122, 19, 29, -111, 49, 98, 105, 26, 42, 58, -100, 28, 18, -90, -104, -11, -16, -37, 2, -113, -125, 61, -47, -73, 60, 55, -55, 45, 74, 70, 96, -72, -89, -37, -71, 57, 118, 79, 74, -36, -41, -113, -21, 43, -7, 18, -84, 119, -27, 35, -38, -81, 34, 103, 117, -110, 38, 127, 126, -55, 33, 24, -61, 77, -102, -58, 58, -88, 100, 32, 44, 66, -92, 124, -26, -118, -19, 115, 3, -81, 82, 25, 58, 53, 57, -71, 107, 116, -76, -91, -100, 15, -36, -78, -110, 22, -34, -48, 37, -84, 37, -118, -7, -45, 50, -114, -4, -121, 77, -44, -94, -14, -40, 115, 21, 12, 37, 68, -54, 110, 91, -89, -59, 76, 34, -68, 110, -66, -50, -28, -70, 104, -30, -120, 37, -112, -35, -102, -50, -19, -43, 98, 65, 28, -8, 34, 107, 76, -126, 4, 101, 108, 54, -105, 79, 73, -97, 67, 65, -90, 19, -94, 46, -71, -104, 32, -94, 88, -116, -44, 62, 96, -29, -16, 28, 21, -92, 117, 54, 51, 3, -98, -55, -83, -108, 52, 67, 0, -3, 63, 55, -58};
        byte[] buffer2 = {67, 84, 98, 122, 24, -61, -42, -77, -102, 86, -10, 28, 20, 63, 12, 29, 59, 54, -125, -79, 57, 81, 74, -86, 9, 62, -2, 68, -81, -34, -61, 32, -99, 66, 58};
        byte[] buffer3 = new byte[132];
        byte[] buffer4 = {-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57};

        handGarble.garble(buffer0, buffer1, buffer2, buffer3, buffer4);

        assertArrayEquals(new byte[]{-106, 95, -58, -14, -8, 70, 32, -128, -33, -66, 10, -8, 2, 31, -106, 121, -124, 115, 32, 35},
                buffer0);
        assertArrayEquals(new byte[]{27, 49, -100, -43, 50, 14, -123, 83, -104, 73, 51, -76, -40, -1, -16, 10, 8, -96, 122, 56, 29, -111, 77, 12, 105, 26, 42, 58, -100, 28, 18, -90, -104, 37, 25, -37, 127, -113, -125, 61, -47, -73, 60, 55, -55, 45, 74, 50, 96, -72, -89, -37, -71, -48, 118, 79, 74, -36, -41, -113, -21, 43, -7, 18, -84, 119, -27, 35, -38, -81, 34, 103, 117, -110, 38, 127, 126, -55, 33, 24, -61, 77, -102, -58, 58, -88, 100, 32, 44, 66, -92, 124, -26, -118, -19, 82, 3, -81, 82, 25, 58, 53, 57, -71, 107, 116, 9, -91, -100, 15, -36, -78, -110, 22, -34, -48, 37, -84, 37, -118, -7, -45, 50, 83, -91, -121, 77, -44, -94, -14, -40, 115, 21, 12, 37, 68, -54, 110, 91, -89, -13, 76, 34, 73, 110, -66, -50, -28, -70, 104, -30, -120, 37, 60, -35, -102, -50, -19, -43, 98, 65, 28, -8, 34, -46, 76, -126, 4, 101, 108, 54, -105, 79, 73, -97, 67, 65, -90, 19, -94, 46, -71, -104, 32, -94, 88, -116, -44, 62, 96, 56, -16, 28, 21, -92, 117, 54, 51, -40, -98, -55, -83, -108, 52, 67, 0, -3, 63, 55, -58},
                buffer1);
        assertArrayEquals(new byte[]{67, 44, -92, 122, 41, -4, -42, -77, 78, 86, -10, 28, -34, 26, -22, 29, -124, 54, 53, -79, 57, 81, 82, -86, 9, -104, -2, 68, 119, -94, -10, 32, -99, 104, -72},
                buffer2);
        assertArrayEquals(new byte[]{85, 0, 0, 0, 86, 0, 0, 0, 8, 0, 0, 0, -78, 0, 0, 0, -110, 0, 0, 0, 56, 0, 0, 0, -120, 0, 0, 0, 30, 0, 0, 0, 92, 0, 0, 0, 50, 0, 0, 0, 116, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, -57, 0, 0, 0, 0, 0, 0, 0, -6, 0, 0, 0, -4, 0, 0, 0, 4, 0, 0, 0, 83, 0, 0, 0, 82, 0, 0, 0, -12, 0, 0, 0, 26, 0, 0, 0, -99, 0, 0, 0, -68, 0, 0, 0, 27, 0, 0, 0, 5, 0, 0, 0, -28, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 109, 0, 0, 0, -4, 0, 0, 0, -52, 0, 0, 0},
                buffer3);
        assertArrayEquals(new byte[]{-19, 37, -47, -69, -68, 39, -97, 2, -94, -87, 17, 0, 12, -77, 82, -64, -67, -29, 27, 73, -57},
                buffer4);
    }
}
