Re: encryption with python
- From: Mike Meyer <mwm@xxxxxxxxx>
- Date: Fri, 09 Sep 2005 17:08:38 -0400
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.
.
- References:
- encryption with python
- From: jlocc
- Re: encryption with python
- From: James Stroud
- Re: encryption with python
- From: jlocc
- Re: encryption with python
- From: Steven D'Aprano
- encryption with python
- Prev by Date: Re: "grep" database
- Next by Date: Re: Question about consistency in python language
- Previous by thread: Re: encryption with python
- Next by thread: Re: encryption with python
- Index(es):
Relevant Pages
|