I've been working to disassemble a decryption algorithm for a particular software. The way it works is that the serial key contains all the appropriate information, gets crunched in the algorithm which outputs plaintext data (It's actually binary data but this is not that important here).I now want to create an algorithm which will re-encrypt arbitrary data.After some work I managed to greatly reduce the code base for the decryption process. Here is how it works :BigUnsigned hash_func(BigUnsigned serial, BigUnsigned running_value, BigUnsigned encrypt_key){    return (serial * running_value) - (((serial * running_value) / encrypt_key) * encrypt_key);}void do_the_thing(){    BigUnsigned key1 = hash_func(buSerial, buSerial, buEncryptKey);    BigUnsigned key2 = hash_func(buSerial, key1, buEncryptKey);    BigUnsigned result = 1;    int key_select = 0;    unsigned int weird_number = 0xc3530000;    for(int i = 0; i < 8; ++i, weird_number *= 4){        result = hash_func(result, result, buEncryptKey);        result = hash_func(result, result, buEncryptKey);        if(weird_number >> 30){            key_select++;            if(key_select < 3){                result = hash_func(result, key2, buEncryptKey);            }else{                result = hash_func(result, buSerial, buEncryptKey);                if(key_select == 4){                    key_select = 0;                }            }        }    }}both buSerial and buEncryptKey are 16 unsigned int (512-bits). I don't get how I can create an algorithm that encrypt new data from this. The problem I have is that key2 is generated from the final result which I don't know beforehand.I'm using this BigInt library
Reverse decryption algorithm
cryptography