Search code examples
algorithmlanguage-agnosticchecksumadler32luhn

Algorithm for message code validation


If you read this thread before - forget everything I wrote, I must have been drunk when I wrote it. I'm starting over:

I'm currently working on a project where we will be using some sort of algorithm for validating user input. There are three parties to consider;

Client - Browsing our web pages

Company - We, handling the Client requests

3rd Party Company - Handling Client messages

On our web pages we will show the Client some information about a product. If he/she wants more information about the product he has to contact the 3rd Party Company and state the products code (not unique per se, but not common either). In return the Client will receive some other code from the 3rd Party Company which he should input on our web page, where we will validate the code for approval.

The best would be if we, the Company, had no interaction with the 3rd Party Company. Pure encryption is out of the picture because it generates a string that is too long. We are doing this by SMS, so the codes has to be short.

What I've come up with so far:

For every product I generate a somewhat unique code (it doesn't matter if it's unique or not really) in base 16 (0-f). The Client who wants more info about the product sends a SMS to the 3rd Party Company stating the products code. In return the Client receives the same code, but the digits are multiplied (possibly by 2) and converted to base 36. On top of that a last character is added to the code, a control number, to make the code valid for the Luhn algorithm in base 36. The user enters the received code and we, the Company, validate it on the server side against the product code (validate against Luhn, divide by 2 and switch back to base 16).

Does this sound reasonably safe and appropriate? Is it a valid way to send messages by three parties, when two of them shouldn't need to communicate?

Sorry for the edit, but my mind must have been elsewhere when I wrote the first post.


Solution

  • After long debates with the 3 Party Company we've concluded that the best solution will be if they pass the Clients SMS to me, I generate a new code and send it back to them which in their turn send a new SMS to the Client with the code I generated. Not optimal from my point of view, but at least I can now do it in any way I want.

    Thanks for your input thou.