All pastes #795030 Raw Edit

Untitled

public python v1 · immutable
#795030 ·published 2007-11-23 16:56 UTC
rendered paste body
#!/usr/bin/python#-*- coding: utf-8 -*-#by JimmySkulldef IntToHex(valor):    return hex(valor).upper()[2:]        def HexToInt(valor):    return int(valor, 16)def StrToHex(frase):    f = ''    for index in frase:        f +=  str(hex(ord(index)))[2:]    return f    def CheckSum(raw):    linha = ':%s??' % StrToHex(raw)    valor = linha[1:-2]    total = 0    l = len(valor)    i = 0    while i < l:        tmp = valor[i] + valor[i+1]        total = total + HexToInt(tmp)        i+=2    CkSm = 256 - HexToInt(IntToHex(total)[-2:])        print "Texto...:",raw    print "Linha...:",linha    print "Soma....: %s (dec=%d)" % (IntToHex(total), total)    print "Conta...: 0x100 - 0x%s" % IntToHex(total)[-2:]    print "CheckSum: 0x%s (dec=%d)" % (IntToHex(CkSm), CkSm)if __name__ == "__main__":    CheckSum('jimmyjamespatrickvanhollghanskull')    ''' Ou...def CheckSum(linha):    valor = linha[1:-2]    total = 0    i = 0    while i < len(valor):        total = total + int(valor[i] + valor[i+1], 16)        i+=2    return hex(256 - int(hex(total)[2:][-2:], 16))'''