1

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.

Vicky
  • 624
  • 2
  • 12
  • 35

1 Answers1

2

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.

faester
  • 14,886
  • 5
  • 45
  • 56
  • This is not related to anything security. The two Guids will just be used to find records from the table. Each Guid will be related to one transaction. We just want to find related transaction by using new Guid generated based on previous Guid. – Vicky Sep 15 '18 at 01:11
  • Great. But I think that one of the comments suggesting an associative array is actually the best solution. Guids are constructed to avoid collisions, but if you derive one guid from another this property disappears: take the (stupid) flip-a-bit approach for the sake of the argument. It would work for the first derived bit, but if you need another derivate it would become the original guid. This would resemble other functions for linking guids. Associating two completely random guids would preserve the non-colliding property. – faester Sep 15 '18 at 07:05
  • But if you really need the linked guids without direct associations I *guess* a good function would be to AES encrypt the guid and use the encrypted value for the associated guid. Translation is then a matter of encrypting and decrypting and AES should make a deterministic yet close to random transformation of the input. But I would still worry about collisions with other guids. – faester Sep 15 '18 at 07:17