0

help about a python script?

hi, could you someone explain this script, line by line? thanks.. #! /usr/bin/env python3 __author__ = 'Felis-Sapiens' from sys import argv def gen_key(mac): charset = '02345679abcdefghijkmnpqrstuvwxyzACDEFGHJKLMNPQRSTUVWXYZ' tmp_key = '' xored_mac = bytearray(mac) for i in range(6, 0, -1): for j in range(i): if i != 6: xored_mac[j] ^= mac[i] tmp_key += charset[xored_mac[j] % 55] key = '' used = [0]*20 j = 7 for i in range(8): key += tmp_key[j] used[j] = 1 cnt = 0 for _ in range(20): j = (j + 1) % 20 cnt += used[j] == 0 if cnt == 8: break return key def main(): if len(argv) < 2: print('Usage:', __file__, 'MAC') return mac = argv[1].replace(':', '').replace('-', '').replace(' ', '') try: mac = bytes.fromhex(mac) except: print('ERROR: Invalid MAC ', argv[1]) return if len(mac) != 6: print('ERROR: Invalid MAC ', argv[1]) return print(gen_key(mac)) if __name__ == '__main__': main()

25th Sep 2020, 6:44 AM
kara kartal
kara kartal - avatar
2 odpowiedzi
+ 2
it's a long script to go through line by line in a reply, there is a lot to explain. where did you get it? the script basically takes a MAC address and generates a key. I ve seen something similar long time ago, some router manufacturers set the default password of their router web interface , ssh... based on the MAC address of their network interface. could you specify what part of the code you didn't understand?
25th Sep 2020, 7:17 AM
Bahhaⵣ
Bahhaⵣ - avatar
0
yes, this is mac to pass script. this part : tmp_key = '' xored_mac = bytearray(mac) for i in range(6, 0, -1): for j in range(i): if i != 6: xored_mac[j] ^= mac[i] tmp_key += charset[xored_mac[j] % 55] key = '' used = [0]*20 j = 7 for i in range(8): key += tmp_key[j] used[j] = 1 cnt = 0 for _ in range(20): j = (j + 1) % 20 cnt += used[j] == 0 if cnt == 8: break if you can explain with a sample, will be good. Mac:98DED0261826 Pass: wkH532Ns 152 222 208 38 24 38 HEX 98DED0261825 zpH930Nv thanks... .
25th Sep 2020, 11:57 AM
kara kartal
kara kartal - avatar