Created
August 9, 2017 18:47
-
-
Save djrtwo/4b80f6dfebc5575e66508edd95a3b0c2 to your computer and use it in GitHub Desktop.
Count zero and non-zero bytes in hex string
This file contains 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
txdata = "606060405260405160808061067283398101604090815281516020830151918301516060909301519092905b42811161003457fe5b60008054600181016100468382610100565b916000526020600020900160005b8154600160a060020a038089166101009390930a928302920219161790555060008054600181016100858382610100565b916000526020600020900160005b8154600160a060020a038088166101009390930a928302920219161790555060008054600181016100c48382610100565b916000526020600020900160005b8154600160a060020a038087166101009390930a928302920219161790555060028190555b5050505061014b565b8154818355818115116101245760008381526020902061012491810190830161012a565b5b505050565b61014891905b808211156101445760008155600101610130565b5090565b90565b6105188061015a6000396000f300606060405236156100a15763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663120b205381146100a35780634ecb35c4146100c557806366d003ac146100f557806367e404ce146101215780636cc6cde11461014d5780637022b58e1461017957806393c0e83a1461018b578063a79a3cee146101ba578063ac4c25b2146101de578063c7fe23a3146101f0575bfe5b34156100ab57fe5b6100b3610220565b60408051918252519081900360200190f35b34156100cd57fe5b6100e1600160a060020a0360043516610226565b604080519115158252519081900360200190f35b34156100fd57fe5b61010561023b565b60408051600160a060020a039092168252519081900360200190f35b341561012957fe5b610105610273565b60408051600160a060020a039092168252519081900360200190f35b341561015557fe5b6101056102ab565b60408051600160a060020a039092168252519081900360200190f35b341561018157fe5b6101896102e3565b005b341561019357fe5b610105600435610364565b60408051600160a060020a039092168252519081900360200190f35b34156101c257fe5b6100e1610396565b604080519115158252519081900360200190f35b34156101e657fe5b610189610410565b005b34156101f857fe5b6100e1600160a060020a0360043516610479565b604080519115158252519081900360200190f35b60025481565b60016020526000908152604090205460ff1681565b60006000600181548110151561024d57fe5b906000526020600020900160005b9054906101000a9004600160a060020a031690505b90565b60006000600081548110151561024d57fe5b906000526020600020900160005b9054906101000a9004600160a060020a031690505b90565b60006000600281548110151561024d57fe5b906000526020600020900160005b9054906101000a9004600160a060020a031690505b90565b6102ec33610479565b15156102f85760006000fd5b600160a060020a0333166000908152600160208190526040909120805460ff19169091179055610326610396565b1561035f5761033361023b565b604051600160a060020a039182169130163190600081818185876187965a03f192505050151561035f57fe5b5b5b5b565b600080548290811061037257fe5b906000526020600020900160005b915054906101000a9004600160a060020a031681565b600080805b60005481101561040357600160006000838154811015156103b857fe5b906000526020600020900160005b9054600160a060020a036101009290920a900416815260208101919091526040016000205460ff16156103fa576001909101905b5b60010161039b565b600282101592505b505090565b33600160a060020a0316610422610273565b600160a060020a0316146104365760006000fd5b600254421161044157fe5b610333610273565b604051600160a060020a039182169130163190600081818185876187965a03f192505050151561035f57fe5b5b5b565b6000805b6000548110156104e15782600160a060020a03166000828154811015156104a057fe5b906000526020600020900160005b9054906101000a9004600160a060020a0316600160a060020a031614156104d857600191506104e6565b5b60010161047d565b600091505b509190505600a165627a7a72305820b02ae8d25b238d57e8363bfc5f30351753ca38bde86d49729841a827fb4e9d660029000000000000000000000000a4be607be0a6cceff581ef35c0cdc47a7532ff540000000000000000000000007c6b393dbb1152691b02a61378bc731662cdd9f1000000000000000000000000748ed23daa18226d872b5bd4d48ff2594fd6901c00000000000000000000000000000000000000000000000000000000597fc480" | |
def count_zero_bytes(data): | |
count = 0 | |
for i in xrange(0, len(data), 2): | |
byte = data[i:i+2] | |
if byte == "00": | |
count += 1 | |
return count | |
def count_non_zero_bytes(data): | |
return (len(data) / 2) - count_zero_bytes(data) | |
print("zero-bytes: {0}".format(count_zero_bytes(txdata))) | |
print("non-zero-bytes: {0}".format(count_non_zero_bytes(txdata))) | |
# OUTPUT | |
# zero-bytes: 184 | |
# non-zero-bytes: 1594 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment