Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jan 2006
    Oslo, Norway
    Thanked 0 Times in 0 Posts

    Crypting with DES in CBC mode

    Hi !

    Is this algorithm difficult to implement in PHP code?
    1. Concatenate the username and the password to produce a plaintext string;
    2. Convert the plaintext string to uppercase characters;
    3. Convert the plaintext string to multi-byte storage format; ASCII
    characters have the high byte set to 0x00;
    4. Encrypt the plaintext string (padded with 0s if necessary to the
    next even block length) using the DES algorithm in cipher block
    chaining (CBC) mode with a fixed key value of 0x0123456789ABCDEF;
    5. Encrypt the plaintext string again with DES-CBC, but using the
    last block of the output of the previous step (ignoring parity
    bits) as the encryption key. The last block of the output is
    converted into a printable string to produce the password hash

    (Point 1 and 2 is, of course, not THAT difficult )

    I came so far:
    PHP Code:
    $chiper MCRYPT_3DES;
    $key1 = ?; //What is this?
    $data "USERNAMEPASSWORD"// (How to fix this acording to point 3 in the algorithm?)
    $mode MCRYPT_MODE_CBC;
    $iv = ?; //: What is this?

    // First time encryption
    $res1 =  mcrypt_encrypt($chiper$key1$data$mode$iv);

    // Get the last block to use as key in second encryption
    $last_block1 substr($res1strlen($res1)-88);

    // Second time encryption
    $res2 mcrypt_encrypt($chiper$last_block1$data$mode$iv);

    // Then get the last block of $res2 and convert to hex
    $last_block2 substr($res2strlen($res2)-88);
    $hash bin2hex($last_block2); 
    Regards Jostein Skaar
    Last edited by jskaar; 01-07-2006 at 12:45 AM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts