Challenge & Response


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Challenge & Response

    not sure that pbp correctly left or right shifts negative numbers , see henriks treatise on the bme280 for correct method to deal with signed ints

    http://www.picbasic.co.uk/forum/showthread.php?t=24134


    ps , i did notice that some cases may lead to doing a left or right shift of a negative number of bits, eg [var << -3 ] i'm not sure how gcc would resolve that
    Last edited by richard; - 29th December 2020 at 23:27.
    Warning I'm not a teacher

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Challenge & Response

    I agree that does look like a problem, thanks for the heads up.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Challenge & Response

    I think I have this cracked now thanks to generous help on this and other forums.

    In the end I did not need the large lookup table as it was always using the same table entry.

    So my code ended up being tiny and did not require LONGS etc. .

    Code:
    W0 VAR WORD
    W1 VAR WORD
    W2 VAR WORD
    
    SEED1 VAR BYTE 
    SEED2 VAR BYTE 
    SEED3 VAR BYTE  
    
    'KEY1 = 46336;
    'KEY3 = 32973;
    'SHIFT1 = 1;   (-1)
    'SHIFT2 = 3;       
        
    ' Calculates and stores the results of two cryptographic operations 
    ' on the first two seed bytes in W1 and W2
    ' 
    ' The operation being carried out consists of adding two 16-bit values
    ' and performing a bitwise rotation on the result.
    ' 
    ' The two results are calculated from adding the 2 seed bytes to both
    ' KEY1 and KEY2, with a rotation of SHIFT1 and SHIFT2 respectively. 
    
    SEED1 = $C7
    SEED2 = $B0
    SEED3 = $6B      
    
    'Answer should be $82 $CB $6B
    
    
    W1.BYTE0 = SEED2
    W1.BYTE1 = SEED1
    
    W0 = W1 + 46336 'Key1            
    
    ' Does a cyclic bitwise rotation of B0-bits on W0
    
    W0 = (W0 >> 1 | W0 << ($10 - 1))   'Note this is a negative shift
    
    W2 = W0
    W0 = W1     
    
    ' Does a cyclic bitwise rotation of B0-bits on W0
    
    W0 = (W0 << 3 | W0 >> ($10 - 3))   'Note this is a positive shift
    
    W1 = W0
    
    ' Multiplies the contents of W1 and W2 and adds KEY3, stores in W0
    ' Impicitly calculates 16-bit overflow only
    
    W0 = W1 * W2
    W0 = W0 + 32973   'KEY3      
    
    SEED1 = W0.BYTE1
    SEED2 = W0.BYTE0

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Challenge & Response

    Are there any optimisations I have missed in the final code in my prev post?

Similar Threads

  1. A new challenge (I'm in trouble again)
    By Davidmarks in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th February 2012, 14:08
  2. 3 phase supply detector challenge
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 15th May 2009, 07:54
  3. Replies: 20
    Last Post: - 13th May 2007, 05:10
  4. Problem with UART... here is a real challenge
    By matias in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th May 2007, 08:30
  5. No Modem response
    By jimboho in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 11th November 2004, 05:58

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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