Are there any cryptographic algorithms like that?
Yes, those algorithms are known are "homomorphic encryption algorithms"; they are public key encryption algorithms (that is, they have a public key and the private key; with the public key, you can encrypt data; to decrypt data, you need the private key).
In addition to the normal public key encryption functionality, they have the property that (with the public key) someone can perform some operations on the encrypted data; for example, with the encryptions $E_k(A)$ and $E_k(B)$, they might be able to compute the ciphertext $E_k(A+B)$ (without learning what $A$ and $B$ are).
You can learn more about the various flavors of homomorphic encryption algorithms out there; however to address your specific examples of +5
and *2
, the obvious answer would be the Paillier cryptosystem, which is a "somewhat" homomorphic system, with the homomorphic operation being addition (modulo a large number; as long as the intermediate values stay under the modulus, we can ignore that). So, to perform a +5
operation on the encrypted value $E_k(A)$, we would take 5, encrypt it with the public key to form $E_k(5)$, and then homomorphically add it to form $E_k(A+5)$. And, to perform a *2
operation on $E_k(A)$, we would just homomorphically add it to itself, forming $E_k(A+A) = E_k(2 \cdot A)$.
Paillier has its limitations (it can't perform any homomorphic operations that can't be expressed as additions); however if you can live with that, it works quite nicely.