+
Skip to content

li0ard/keeloq

Repository files navigation

@li0ard/keeloq logo

@li0ard/keeloq
Playground for KeeLoq cipher
docs • online tool




Warning

The library has been created for educational purposes only. The author negatively refers to any unauthorized and/or criminal actions with systems using KeeLoq. Also the author is not responsible for your actions.

Caution

Please do not distribute manufacturer keys, this may result in legal consequences for you

Installation

# from NPM
npm i @li0ard/keeloq

# from JSR
bunx jsr i @li0ard/keeloq

Examples

Decrypt "Simple learning"

import { simple_learning } from "@li0ard/keeloq"

let key = 0x123456789ABCDEFn; // Manufacturer key
let hop = 0xf16c47a6; // Encrypted hop
let decrypted = simple_learning(hop, key);
console.log(decrypted) // -> { btn: 2, serial: 491, cnt: 10, raw: 569049098 }

Usage of high-level API class

import { KeeloqImpl, LearningTypes } from "@li0ard/keeloq"

let impl = new KeeloqImpl(
    0x123456789ABCDEFn, // Manufacturer key
    LearningTypes.SIMPLE_LEARNING, // Learning type
    0x39b3deb, // Serial number
    2, // Button number
    10 // Counter value
)

console.log(impl.key) // -> 0x65e2368fd7bcd9c4n
impl.cnt_incr(2) // Increasing counter by 2
console.log(impl.key) // -> 0x1532f97fd7bcd9c4n

Custom implementation

Tip

Check this for examples

The library allows users to create their own implementations of KeeLoq. To do this, create a class extending from AbstractKeeloqImpl and implement corresponding methods and getters.

Example (for Beninca):

import { AbstractKeeloqImpl, magic_xor_type1_learning, encrypt } from "@li0ard/keeloq";

class BenincaImplementation extends AbstractKeeloqImpl {
    constructor(public mfkey: bigint, public serial: number, public btn: number, public counter = 1) {
        super(mfkey, serial, btn, counter)
    }

    public get hop_raw(): number {
        return this.btn << 28 | 0x0 << 16 | this.counter;
    }

    public get hop(): number {
        let key: bigint = magic_xor_type1_learning(this.serial, this.mfkey);
        return encrypt(this.hop_raw, key)
    }
}

Acknowledgements

Some parts were based on or greatly inspired by these projects:

  • unleashed-firmware - Original implementation of low-level primitives in C and library logo

About

Playground for KeeLoq cipher

Topics

Resources

License

Stars

Watchers

Forks

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载