Vicky
Vicky

Reputation: 734

Generate another Guid using one Guid and vice versa

Is there a way/algorithm/method to generate a new Guid (x) using our old GUid (y) and then get y back whenever we want from x?

Something similar to below answer but it shows a way to old Guid(I can consider it as a string) to convert to Guid but not a way back.

https://stackoverflow.com/a/9386095/5887074

How can I generate a GUID for a string?

P.S.: This is not related to anything security. The two Guids will just be used to find records from the table. We can convert Guid to string in this conversion if required.

Upvotes: 1

Views: 1362

Answers (1)

faester
faester

Reputation: 15076

There are thousands of ways: a guid is 128 bits, so you could flip one bit which would make it simple to translate back and forth. Or you could do modulo 42 and make it look as if you made something unpredictable. Or you could reverse the order of the bits, do a NOT operation on all of them or rearrange the bits by some predefined pattern.

But I suspect that you have a use case which you do not define. Please tell a bit more about the problem you want to solve. Your request sounds a little bit dangerous as it sounds as if you want to enable some kind of tracking between seemingly unrelated entities. If there is some security issues involved you are very likely to get it wrong if both cleartext (guid pre translation) and cipher (guid after translation) are public. Perhaps simple AES encryption would suffice as a translation function, but I think you need to specify you problems in much more details to get a useful answer.

Upvotes: 2

Related Questions