Inserting a calculated value
Here's how I would go about this:


Configure a field on the contact. Select "set via PHP" or whatever the option's exact name is.
Generate an extension using Civix. Remember portability - your extension can generate the field in (1), meaning that if you decided to share the extension or use it on multiple projects that.
Use the hook as Ramesh said to fill the values in the field.


It sounds like a neat extension. If you want to commission CiviFirst for this I'd be more than happy to help!

JohnFF