Keeloq Encoder example code


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807

    Default Keeloq Encoder example code

    Hi.

    I am trying to make a Keeloq encoder in software but my approach seems wrong I guess.

    I have an assembly code that is used to decode the encrypted data and though that if I use this routine on the encrypted data I may get the initial data back.

    Obviously this is not working. I did not posted the code because it is licensed from Microchip.

    So, if anyone knows how to encode using keeloq but without special chips like the 636, please reply.

    Ioannis

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Keeloq Encoder example code

    of course its been done on an arduino
    https://www.google.com.au/url?sa=t&r...4vCzBoCCF07SvA

    this link may help

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Keeloq Encoder example code

    Thank Richard.

    A bit cryptic that C but will try to understand what is going on!

    Ioannis

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Keeloq Encoder example code

    I think this is pretty close for decrypt , but don't ask me how it works or why it loops 528 times

    Code:
    x  var long
    r  var long
    keyBitVal  var long
    bitVal     var long
    key    var byte[8] ;key is long + long  = 64 bits you need to input this somehow
    index  var word
    KeeLoq_NLF     const         $3A5C742E
     
     
    decrypt:  ;  input to decrypt is in var x  ->   output is in var x
    while  r<528
       keyBitNo = (15-r) & 63
       keyBitVal = key.0[keyBitNo]
       index = 1 * x0.[1] + 2 * x.0[9] + 4 * x.0[20] + 8 * x.0[26] + 16 * x.0[31]    
       bitVal = x0.[0] ^ x.0[16] ^ KeeLoq_NLF.0[index] ^ keyBitVal
       x = (x>>1) ^ bitVal<<31;
       r=r+1
    wend
     return

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Keeloq Encoder example code

    x = (x>>1) ^ bitVal<<31;
    a clever person could knock up some code to do 32 bit shift left , right and a 32 bit xor then the whole thing could be done without pbpl at all
    Last edited by richard; - 11th November 2015 at 08:37. Reason: still can't type

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Keeloq Encoder example code

    Thanks Richard for the effort on this.

    I'll try to do the same on the encryption part which is what I am interested in.

    About PBPL, sure I will try to do this in PBP since the code is inteded to run on a low end PIC.

    Thanks again,
    Ioannis
    Last edited by Ioannis; - 11th November 2015 at 08:40.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Keeloq Encoder example code

    I feel there is something missing here , the code is meant to be rolling encryption . so something needs to be saved for the next call doesn't it ?

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Keeloq Encoder example code

    The general idea from the limited data I could find is this.

    You have your secret keys (8 bytes) that both the encrypter and decrypter know.

    Then you have also 4 bytes of data (32 bits) that will be encoded byt the encoder (either hardware or software).

    The result will be placed (after the crazy 512 shifts and rotatons) at the same registers of the 4 data bytes. They call it CSR3:CSR0 registers in the data sheet and ANs.

    Regarding the decryption I am very close, almost working. But the Encoder is a bit harder to accomplish, mainly because resources are limited on a 12Fxxx chips.

    Thanks,
    Ioannis

Similar Threads

  1. Absolute encoder with Petherick code
    By stojakovicv in forum mel PIC BASIC
    Replies: 3
    Last Post: - 1st April 2016, 16:36
  2. Rentron Encoder
    By lerameur in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 27th June 2013, 07:28
  3. Convert Rotary Encoder Code from 16F628A to 16F1825
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 7th June 2012, 04:34
  4. rf encoder/decoder
    By a_critchlow in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd February 2006, 11:58
  5. KeeLoq
    By wvdv in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 30th November 2004, 23:46

Members who have read this thread : 1

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