the key is quite easily :) computed from the lock key[x]= ns(lock[x]^lock[x-1]) ns is a nibble swap (switch the upper 4 bits with the lower 4 bits) exception: ey[0] is a bit different let's name A and B the 2 last bytes of the lock key[0]= ns(lock[0]^A^B^0x05) ; 0x05 is a kind of magic nibble #### $key_arr[0] = pack 'h2', unpack 'H2', ( $lock_arr[0] ^ $lock_arr[@lock_arr - 1] ^ $lock_arr[@lock_arr - 2] ); for (my $i=1; $i<@lock_arr; $i++) { $key_arr[$i] = pack 'h2', unpack 'H2', ($lock_arr[$i] ^ $lock_arr[$i-1]); }