Given an input item (N bytes), I'm looking for a function that will map this to an output (still N bytes). The function should have the following qualities:

  • It should be 1-to-1 so that all inputs map to some output and so that no two inputs map to the same output.
  • Given an output element it should be difficult to guess the input that lead to that output, even when the mapping is completely known.

Does such a function exist? Where can I learn more?

  • $\begingroup$ By the way, I'm an engineer by trade, and I only have an applied background in computer science. So please excuse my loose/incorrect use of terminology. $\endgroup$ – JnBrymn Dec 19 '15 at 21:19
  • 3
    $\begingroup$ Is this just for curiosity or do you have some reason for wanting to do this? If you want to deploy this in some system, I strongly recommend that you ask on Information Security whether the thing you're asking about here is a reasonable solution to the problem you're trying to solve with it. $\endgroup$ – David Richerby Dec 20 '15 at 9:52

This is known as a one-way permutation. The "permutation" refers to the first of your two requirements; the "one-way" refers to the second of your two requirements. There are various candidate constructions for one-way permutations, e.g., based on raising to the third power modulo an RSA modulus or other schemes.

  • $\begingroup$ It's also worth looking up Feistel networks. They are a standard method for turning general functions into permutations. $\endgroup$ – Pseudonym Dec 19 '15 at 23:38
  • 2
    $\begingroup$ @Pseudonym, Feistel networks require a key and they're not one-way: you need the key to compute the map, and with the key, you can easily go backwards. So, they solve a quite different problem. $\endgroup$ – D.W. Dec 20 '15 at 0:07
  • $\begingroup$ The strict definition of a Feistel network is that it requires a key, but their only use is as an input to the round functions. It's trivial to modify the structure to use functions without a parameter. $\endgroup$ – Pseudonym Dec 20 '15 at 0:21
  • 1
    $\begingroup$ @Pseudonym, yes, but with that modification it's not one-way. It's as easy to compute the reverse map as it is to compute the forward map. They are a very cool technique, but they don't solve this particular problem. $\endgroup$ – D.W. Dec 20 '15 at 0:27
  • $\begingroup$ Ah, of course! I missed that detail, sorry. $\endgroup$ – Pseudonym Dec 20 '15 at 4:21

You may want to have a look on DES or AES, they are doing exactly what you want. these to methods depending on having a key that encrypt/decrepit the plain text. another method the use dual keys (public&private keys) this is a very commonly used method nowadays and the most popular one is RSA, it is mainly deepening on having a public key the is known to every one and a privet key it is just you who should know it. and if you some one want to send you something he will encrypt it with your public key (notice that he cannot decrepit it anymore as it is only decrepited by your private key). and if you want to make authentication you can send something encrypted by your private key and the receiver will decrepit it by your public key that way he will be sure that it is sent by you.

more information could be found here:


  • 1
    $\begingroup$ AES and DES require a key and they're not one-way: you need the key to compute the map, and with the key, you can easily go backwards. So, they solve a quite different problem. $\endgroup$ – D.W. Dec 20 '15 at 0:07

You could try this:

First, take the SHA-256 or other hash of your input value. Then use a basic cypher, something like the classic A=C, B=D, C=E...

The difference is that you use the SHA-256 of the entire input string to determine how much it is shifted by(is it A=B, A=C, A=D, etc.)

Note: I am not a cryptography expert and am not sure how secure this would be.

  • 1
    $\begingroup$ This is horrifically insecure. It doesn't matter how fancy a method you use to determine the key of a Caesar cypher: there are still only 26 options and you can decrypt by just trying each one in turn. Also, the question asks for something one-to-one, which this might not be, and it asks for something one-way, which this certainly isn't. Rule 1 of crypto: don't "roll your own". $\endgroup$ – David Richerby Dec 20 '15 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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