// Path: encoder/src/main/java/ru/bullyboo/encoder/utils/ArrayUtils.java
// public class ArrayUtils {
// 
//     public static int[] mergeArrays(byte[] mainArray, int[] appendArray){
// 
//         int[] array = new int[mainArray.length + appendArray.length];
// 
//         int mainSize = mainArray.length;
//         int appendSize = appendArray.length;
// 
//         for(int i = 0; i < mainSize; i++){
//             array[i] = mainArray[i];
//         }
// 
//         System.arraycopy(appendArray, 0, array, mainSize, appendSize);
// 
//         return array;
//     }
// 
//     public static int[] mergeArrays(int[] mainArray, int[] appendArray){
//         int[] array = new int[mainArray.length + appendArray.length];
// 
//         int mainSize = mainArray.length;
//         int appendSize = appendArray.length;
// 
//         System.arraycopy(mainArray, 0, array, 0, mainSize);
// 
//         System.arraycopy(appendArray, 0, array, mainSize, appendSize);
// 
//         return array;
//     }
// 
//     public static int[] convertListToArray(List<Integer> integerList){
//         int[] array = new int[integerList.size()];
// 
//         for(int i = 0; i < integerList.size(); i++){
//             array[i] = integerList.get(i);
//         }
// 
//         return array;
//     }
// }


import java.util.ArrayList;
import java.util.List;
import ru.bullyboo.encoder.utils.ArrayUtils;
/*
 * Copyright (C) 2017 BullyBoo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ru.bullyboo.encoder.hashes;



/**
 * The SHA256 Message-Digest Algorithm
 */
class SHA256 {

    private static final int[] K = {
            0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
            0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
            0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
            0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
            0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
            0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
            0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
            0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
    };

    /**
     * Message Digest Buffer
     */
    private int A;
    private int B;
    private int C;
    private int D;
    private int E;
    private int F;
    private int G;
    private int H;

    /**
     * This method return hash of message
     */
    public String getHash(String input){

        byte[] bytes = input.getBytes();

        List<Integer> intList = appendPaddingBits(bytes);

        intList = appendLength(intList, bytes.length * 8);

// Path: encoder/src/main/java/ru/bullyboo/encoder/utils/ArrayUtils.java
// public class ArrayUtils {
// 
//     public static int[] mergeArrays(byte[] mainArray, int[] appendArray){
// 
//         int[] array = new int[mainArray.length + appendArray.length];
// 
//         int mainSize = mainArray.length;
//         int appendSize = appendArray.length;
// 
//         for(int i = 0; i < mainSize; i++){
//             array[i] = mainArray[i];
//         }
// 
//         System.arraycopy(appendArray, 0, array, mainSize, appendSize);
// 
//         return array;
//     }
// 
//     public static int[] mergeArrays(int[] mainArray, int[] appendArray){
//         int[] array = new int[mainArray.length + appendArray.length];
// 
//         int mainSize = mainArray.length;
//         int appendSize = appendArray.length;
// 
//         System.arraycopy(mainArray, 0, array, 0, mainSize);
// 
//         System.arraycopy(appendArray, 0, array, mainSize, appendSize);
// 
//         return array;
//     }
// 
//     public static int[] convertListToArray(List<Integer> integerList){
//         int[] array = new int[integerList.size()];
// 
//         for(int i = 0; i < integerList.size(); i++){
//             array[i] = integerList.get(i);
//         }
// 
//         return array;
//     }
// }


// Path: encoder/src/main/java/ru/bullyboo/encoder/hashes/SHA256.java
import java.util.ArrayList;
import java.util.List;
import ru.bullyboo.encoder.utils.ArrayUtils;

/*
 * Copyright (C) 2017 BullyBoo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ru.bullyboo.encoder.hashes;



/**
 * The SHA256 Message-Digest Algorithm
 */
class SHA256 {

    private static final int[] K = {
            0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
            0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
            0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
            0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
            0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
            0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
            0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
            0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
    };

    /**
     * Message Digest Buffer
     */
    private int A;
    private int B;
    private int C;
    private int D;
    private int E;
    private int F;
    private int G;
    private int H;

    /**
     * This method return hash of message
     */
    public String getHash(String input){

        byte[] bytes = input.getBytes();

        List<Integer> intList = appendPaddingBits(bytes);

        intList = appendLength(intList, bytes.length * 8);

        int[] array = ArrayUtils.convertListToArray(intList);