Created
April 14, 2021 13:16
-
-
Save typelogic/db73132a1406f37061440f9ed87cf5f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Mifare classic access bits | |
| # Example: accessbits([0,0,0,1]) | |
| def accessbits(acbits): | |
| bm=[[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]] | |
| invert = lambda arr: [[1,0][x] for x in arr] | |
| def convert(arr): | |
| s=0 | |
| for n in range(len(arr)): | |
| s=s+arr[-1-n]*2**n | |
| return s | |
| ac=[bm[x] for x in acbits] | |
| arrn=[[],[],[],[]] | |
| for i in [2,1,0]: | |
| for j in [3,2,1,0]: | |
| arrn[i].append(ac[j][i]) | |
| b6=convert(invert(arrn[1]) + invert(arrn[0])) | |
| b7=convert(arrn[0] + invert(arrn[2])) | |
| b8=convert(arrn[2] + arrn[1]) | |
| return [hex(b6), hex(b7), hex(b8)] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment