I came across your post yesterday and though it’d be fun to revers engineer the protocol from scratch just for fun. Since I have lots of different models of Linear transmitters and receivers lying around.

I’m sure someone has done this already. But I just wanted to post this for others that maybe interested in the protocol.

I’m sure someone will read this and disagree with the formula I came up with. Or the processes I used to come up with it. But it seams to work properly.

I don’t know much about coding. But I kind of hope maybe someone finds my formula useful. Or maybe able to use it some how implement a way to selectively manually add remotes directly on the flipper based on decimal numbers for facility code, transmitter, and button

This may be helpful if someone needs to generate a key without internet access as well as understand how a Linear MegaCode key can be generated.

How to use Google Sheet to automate the calculations and conversion of Linear MegaCode to hex.

```
01] Copy the formula into any cell other than A3 or B3 or C3. (e.g. D3)
=DEC2HEX((SUM(B3*8)+8388608)+(A3*524288)+C3)
02] Then enter a facility code into cell A3. (e.g.3)
03] Then enter a transmitter number into cell B3. (e.g.17316).
04] Then enter a button number into cell C3 (default button number for a single button remote is 2
05] If configured correctly 9A1D22 should be displayed in cell D3
06] Done -- make or edit file using the generated key 9A1D22
```

---->

Filetype: Flipper SubGhz Key File

Version: 1

Frequency: 318000000

Preset: FuriHalSubGhzPresetOok650Async

Protocol: MegaCode

Bit: 24

Key: 00 00 00 00 00 9A 1D 22

---->

=DEC2HEX((SUM([Transmitter number]*8)+8388608)+([Facility code]*524288)+[Button number])

Manually calculate

(e.g 1) a transmitter with the number 17316 and a facility code 3 Button 2.

```
01] To convert Facility number to hex use formula (math in DEC)----> (( 17316 * 8 ) + 128 ) = 152
02] To convert transmitter number to hex use formula (math in DEC)--> (( 17316 * 8 ) + 2 ) = 138530
03] Now convert the facility number 152 from step one to HEX. You should get -------> 98
04] Now convert the transmitter number 138530 from step two to HEX. You should get --> 21D22
05] Now when the two numbers are combined we see ---> 98 21D22 that's sevin digits. But six is needed.
06] So to shrink sevin digits down to six. Take the last digit of the facility code (8) and first digit of transmitter (2) and add them together (remember this math is HEX)--> 8 + 2 = A
07] Now take the number generated in step six and replace the last digit of the facility number (remember this is HEX)---> 9A
08] Now append the leftover digits of card number (this is HEX) --> 9A 1D 22
09] To complete the key, append ten zeros before the number generated. Make sure there is a space after every two digits. ---> 00 00 00 00 00 9A 1D 22
10] Done - create or modify file
```

Note: If card and facility are less than 6 then fill the digit between facility code and transmiter code with 0’s

(e.g Transmitter 1, Facility 0, Button 2 = 80A. 80 is the facility A is the transmitter. So to correct it, it would be 80 00 0A

Optional:

If a button other than 2 is desired the last digit can be changed by adding or subtracting the list digit. (0-7) (Two is factory default for single button transmitters)

```
B1] To change button to 1 subtract 1 from the last digit (this is HEX) ---> 00 00 00 00 00 9A 1D 21
B2] To change button to 2 leave the last digit alone (this is HEX) -------> 00 00 00 00 00 9A 1D 22
B3] To change button to 3 add 1 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 23
B4] To change button to 4 add 2 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 24
B5] To change button to 5 add 3 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 25
B6] To change button to 6 add 4 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 26
B7] To change button to 7 add 5 to the last digit (this is HEX) -----------> 00 00 00 00 00 9A 1D 27
```