Re: encryption with python



Steven D'Aprano <steve@xxxxxxxxxxxxxxxxxxxxxx> writes:
> On Wed, 07 Sep 2005 14:31:03 -0700, jlocc wrote:
>> Basically I will like to combine a social security number (9 digits)
>> and a birth date (8 digits, could be padded to be 9) and obtain a new
>> 'student number'. It would be better if the original numbers can't be
>> traced back, they will be kept in a database anyways. Hope this is a
>> bit more specific, thanks!!!
> last_number_used = 123 # or some other appropriate value
>
> def make_studentID():
> global last_number_used
> last_number_used = last_number_used + 1
> return last_number_used
>
> For a real application, I'd check the database to see if the number has
> already been used before returning the number. Also, if you need more
> than four digits in your IDs, I'd add a checksum to the end so you can
> detect many typos and avoid much embarrassment.
[...]
> In a real application you would need to store the global variables in a
> database, otherwise each time you reload the Python script you start
> generating the same IDs over and over again.

For real applications (ignoring your theoretical need to generate the
numbers in a random order) I'd not only store the number in the
database - I'd let the databae generate it. Most have some form of
counter that does exactly what you want without needing to keep track
of it and check the database for consistency.

<mike
--
Mike Meyer <mwm@xxxxxxxxx> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
.



Relevant Pages

  • Re: How should I generate a primary key?
    ... the external reality and verify them. ... be verified for syntax or check digits inside itself. ... A surrogate key is system generated to replace the actual key behind ... with a quote from Dr. Codd: "..Database users ...
    (comp.databases)
  • Re: encryption with python
    ... > and a birth date (8 digits, could be padded to be 9) and obtain a new ... quick-and-dirty student ID algorithm: ... I'd check the database to see if the number has ... an attacker might be able to work out roughly what ...
    (comp.lang.python)
  • Re: Big numbers
    ... My problem is how to store it in C. ... It's not important that it comes from a database. ... close to keep the last three digits accurate. ... It is extremely unlikely that your data base query returns it's ...
    (comp.lang.c)
  • Default Value of field based on another field of same record
    ... Retirement Default value to be set to last day of the month when age is ... of date Batch field above). ... how can I extract the first four digits from the field 'OfficerID' ... I can post the database if required. ...
    (microsoft.public.access.gettingstarted)
  • Re: Parts Numbering Scheme
    ... >numbering scheme. ... The next two digits indicate a major subsystem or group of related parts ... A big reason why local phone numbers in the US are ... I would create a database to go with this, with the part number as the ...
    (sci.electronics.design)