0
$\begingroup$

I am a newbie to the encryption-decryption algorithm. Below is the code for it. Can you help me to figure out the algorithm used?

public class Pseudo {

    public void encrypt(String plaintext) {
        int[] key = new int[]{val1, -val2, -val3, val4};
        byte[] passwordByteArray = plaintext.getBytes();
        int padding = 8 - passwordByteArray.length % 8;
        int paddedLength = passwordByteArray.length + padding;
        byte[] paddedPassword = new byte[paddedLength];
        System.arraycopy(passwordByteArray, 0, paddedPassword, 0, paddedLength);
        for (int offset = 0; offset < paddedPassword.length; offset += 8) {
            // 2 32-bit integers represent 64 bits
            int[] blockOf64bits = get8BytesAsInts(paddedPassword, offset)
            int k = 0;
            int increment = -1640531527;
            int first4Bytes = blockOf64bits[0];
            int second4Bytes = blockOf64bits[1];
            // run this function for 32 rounds
            for (byte round = 0; round < 32; round++) {
                k += increment;
                first4Bytes += ((second4Bytes << 4) + key[0]) ^ (second4Bytes + k) ^ ((second4Bytes >> 5) + key[1]);
                second4Bytes += ((first4Bytes << 4) + key[2]) ^ (first4Bytes + k) ^ ((first4Bytes >> 5) + key[3]);
            }
            byte[] encryptedBlock = intToBytes(first4Bytes, second4Bytes);
        }
    }

    public void decrypt(byte[] cipherText) {
        int[] key = new int[]{2023708229, -158607964, -2120859654, 1167043672};
        for (byte offset = 0; offset < cipherText.length; offset += 8) {
            int[] arrayOfInt = get8BytesAsInts(cipherText, offset);
            int first4Bytes = arrayOfInt[0];
            int second4Bytes = arrayOfInt[1];
            int k = 0;
            int m = -1640531527;
            k = -957401312;
            for (byte b1 = 0; b1 < 32; b1++) {
                second4Bytes -= ((first4Bytes << 4) + key[2]) ^ (first4Bytes + k) ^ ((first4Bytes >> 5) + key[3]);
                first4Bytes -= ((second4Bytes << 4) + key[0]) ^ (second4Bytes + k) ^ ((second4Bytes >> 5) + key[1]);
                k -= m;
            }
            byte[] decryptedBlock = intToBytes(first4Bytes, second4Bytes);
        }
        byte padding = cipherText[0];
    }

    int[] get8BytesAsInts(byte[] password, int offset) {
        return null;
    }

    byte[] intToBytes(int first, int second) {
        return null;
    }

}
New contributor
Satarupa is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
  • $\begingroup$ Some sort of insecure toy block cipher. Probably created specifically for an exercise to break it. $\endgroup$ – SAI Peregrinus yesterday
  • 2
    $\begingroup$ It looks like TEA. $\endgroup$ – benrg yesterday
  • $\begingroup$ thanks, it is TEA $\endgroup$ – Satarupa yesterday

Browse other questions tagged or ask your own question.