I want to use cryptographic function that returns the initial input or something related to it like its hash, the function should work like Encrypting some data or its hash, then encrypt the output of the data, and encrypt it again another time, and the loop continue to specific number of iterations and finally it can produce the first input after iterating it, that is meaning in the end of the loop it will decrypt that original input.

Assuming that we can use any different keys or same key if required in encryption and the function can only go in one way it can't be reversible so i can't run this process from the back loop and finally it should return the first input or something related to its first input by checking the hash of it or something like that.

I just mean by reversible it can only go from data1 to data2 to data3 an so on.. until data(x-1) to datax then data1 again, I don't want it to be go also from back like data1 to datax to data(x-1) an so on until data2 to data1 again.

  • 1
    $\begingroup$ If the function loops after some number of invocations, that allows to reverse it from step $x+1$ to step $x$ by iterating from step $x+1$ in the forward direction until looping; the previous value is that of step $x$. $\endgroup$
    – fgrieu
    Commented Jul 22, 2022 at 16:38
  • $\begingroup$ actually i don't understand what do you mean, but any way for more information is it possible to encrypt data multi time (n time) with different key or same key to restore first input ? $\endgroup$ Commented Jul 22, 2022 at 19:13
  • $\begingroup$ @MohamedA.Taha imagine the function called Loop3 and you know what Loop3(Loop3(X)) equals, but you want to know what Loop3(X) is. Then you calculate Loop3(Loop3(Loop3(X))) which is X, then based on X you calculate Loop3(X). That is how you can go backwards. $\endgroup$ Commented Jul 22, 2022 at 20:08
  • $\begingroup$ 1) Can we read "the function can only go in one way it can't be reversible" as "the most efficient way to reverse the function must be to run it in the forward direction until it cycles"? 2) About how much time should it require a standard PC to make one evaluation of the function? 3) About how much should be the "specific number of iterations" ? 4) Does that number need to be public ? (applies only if the product of the two previous quantities is prohibitively large) 5) Can parameters of the function be built by a trusted party that keeps some secret that would allows faster inverting? $\endgroup$
    – fgrieu
    Commented Jul 24, 2022 at 18:17
  • $\begingroup$ @fgrieu 1) yes you have to run the full cycle. 2)about xxx millisecond to 0.5 sec or maybe 1sec maximum 3) to be specific it could be sequential of encrypted data and ends with the start data not completely loop like i said, i just use term loop to mean we can use the same function in sequential no matter how it long. 4) yes it should be public and also keys should be public 5) no it shouldn't be previous actually it's a consensus mechanism for blockchain idea $\endgroup$ Commented Jul 24, 2022 at 21:58

2 Answers 2


The requirements

  1. some "specific number of iterations (..) produce the first input"
  2. "the function can only go in one way; it can't be reversible"

are not compatible (except if an iteration of 1 requires a secret/key, and that secret is not available during the attempted reversal of 2, which the question does not suggest).

Thus what's asked can not be obtained.

Argument: for any public function $f$ from and to some domain that has property 1, and any $y$ in the domain, we can find a solution $x$ to $y=f(x)$ by

  • let $x=y$ and $z=f(y)$
  • while $z\ne y$
    • let $x=z$ and $z=f(z)$
  • output $x$ and stop

That will loop some limited number of times (at most the specific number of iterations, and always a divisor thereof).

Note: The question is not very precise and leaves some leeway with "or its hash"; thus things are not as clear-cut as above. But I fail to find a precise problem statement matching the question and that's not provably impossible to meet by a similar argument.

I'm ready to revise that answer if the question is revised and made precise, e.g. distinguishes operations that require a secret and operations that do not, or otherwise restricts requirements to prevent the impossibility that I describe.

  • $\begingroup$ I think you and OP must agree on what do we mean reversible because reversible in general has a different meaning from what the meaning it has in cryptography cause most of the cryptographic functions are reversible but not in polynomial time. $\endgroup$
    – tur11ng
    Commented Jul 23, 2022 at 13:55
  • $\begingroup$ thanks for your attention, ok i will explain in easy way we all know the VDF function, that function take specific time to compute. Solana blockchain works like input random data then get it's hash then get the hash of hash and it can get the 300 or 400 hash of it's first input this process take time, but it doesn't take time to verify if the node get all hashes and rerun in parallel using GPU. $\endgroup$ Commented Jul 23, 2022 at 14:52
  • 1
    $\begingroup$ it's not efficient way to do that, i search for function that run in sequential order like this hash but i think if it cryptographic encryption will be better because we can get the data again, then the user has to give the last encrypted data before using the last key to return the first input, then the user take the time required to proof that he make a solution and other nodes can verify the solution in just one step no need for GPUs and no need for tradition way of finding nonce of the block $\endgroup$ Commented Jul 23, 2022 at 14:57

Every cryptographic hash with a fixed domain is like this.

I.E, after too many iterations iterating x = hash(x), the original x will be reached. Problem is, for a strong hash the number of iterations in said loop is not known and could be insanely long (huge number of iterations until a loop is found).

  • $\begingroup$ A number of the prescriptions of the question are not met by a standard hash: 1) "the end of the loop it will decrypt that original input" (or it"s hash) 2) looping does not occur after "some specific number of iterations" (at least, not a practical number). $\endgroup$
    – fgrieu
    Commented Jul 24, 2022 at 7:30
  • $\begingroup$ @fgrieu yes, that's right i have to satisfy all conditions required if should have fixed length of iteration and it have to return something related to first input or the input itself $\endgroup$ Commented Jul 24, 2022 at 15:06
  • $\begingroup$ For a random permutation, all points will be on some cycle. For a random function, most points will not be on any cycle. If I understood this reference correctly, only $O(\sqrt{n})$ points are expected to be on a cycle, in a random function over $n$ items. $\endgroup$
    – Mikero
    Commented Jul 25, 2022 at 0:59
  • $\begingroup$ For a random function, it is far from guranteed the starting point is on a cycle, it will lead to a cycle, but the starting but need not be on a cycle at all. In fact the starting point may not even have any pre-image(though that is less likely). $\endgroup$
    – Meir Maor
    Commented Aug 23, 2022 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.