Micz has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have a specific application which I wanted to protect with a OTP system, but which can only use numbers. What I am trying to do is that the user gets a number (sensible length, perhaps 8 digits), uses an OTP tool on his palm to generate a response with a password he knows, and enters this number. any ideas / code which will point me in the right direction? The CPAN OTP module will generate chars... thanks for your help! jan
  • Comment on OTP (S/Key) implementation using just numbers

Replies are listed 'Best First'.
Re: OTP (S/Key) implementation using just numbers
by jeroenes (Priest) on Jun 13, 2001 at 18:45 UTC
    A few comments:
    1. OTP may not be secure if you use small 'pads' or numbers (like less than 1000 chars). Weigh security against userfriendliness. PGP can compensate for too small info.
    2. I don't think I have to mention that security is as strong as the weakest link, but just to be sure.
    3. Chars are easy to convert to numbers, eg see CGIPack.
    4. Or if you have 8 chars in the 0-255 ASCII range, just use pack/unpack once (quad integer, 64 bit platforms) or twice (long integer). If you have an 8-digit integer, short is enough.

    Hope this helps,

    Jeroen
    "We are not alone"(FZ)

Re: OTP (S/Key) implementation using just numbers
by DaveHowe (Initiate) on Jun 13, 2001 at 21:16 UTC
    What you are describing is a challenge-response pair - for which OTP is not really suited. Consider instead the following:
    1. Hand the user a number
    2. user types in number and his Password into a program
    3. program concats number and password to form a string, then hashes it (MD5 or something better)
    4. program converts resulting hash to decimal, and takes the lowest 'n' decimal digits to display (where 'n' is say 8-10)
    5. user hands back decimal digits
    6. server program does same calculation
    7. if numbers match, you are probably ok ;)
      Thank you for your replies! In case somebody needs some code to get started, here's mine. Please don't scream when you see my perl...

      regards, jan
      use Digest::MD5 qw(md5 md5_hex md5_base64); srand(); $pass = "micz"; $random[0]=int(rand(9)); $random[1]=int(rand(9)); $random[2]=int(rand(9)); $random[3]=int(rand(9)); $num = $random[0].$random[1].$random[2].$random[3]; $concat = $num.$pass; $hash = md5($concat); $response[0] = ord(substr($hash, 2, 1)); $response[1] = ord(substr($hash, 7, 1)); $response[2] = ord(substr($hash, 7, 1)); $response[3] = ord(substr($hash, 9, 1)); $totalresponse = print "Our challenge is $random[0]-$random[1]-$random[2]-$random[3] (p +sst, the password is $pass) \n"; print "The correct response is $response[0]-$response[1]-$response[2]- +$response[3] \n"; exit;