Created
June 6, 2025 09:12
-
-
Save Meroje/89c820e4e8b7ef513c44e2f707b9b375 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
import base64 | |
import binascii | |
def AWSAccount_from_AWSKeyID(AWSKeyID): | |
trimmed_AWSKeyID = AWSKeyID[4:] #remove KeyID prefix | |
x = base64.b32decode(trimmed_AWSKeyID) #base32 decode | |
y = x[0:6] | |
z = int.from_bytes(y, byteorder='big', signed=False) | |
mask = int.from_bytes(binascii.unhexlify(b'7fffffffff80'), byteorder='big', signed=False) | |
e = (z & mask)>>7 | |
return (e) | |
print ("account id:" + "{:012d}".format(AWSAccount_from_AWSKeyID("ASIAQNZGKIQY56JQ7WML"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment