(self, cipher=None)
return result
HH3C ASCII to Binary converter

        Args:
          @cipher = ASCII Ciphertext to convert to binary

        Returns:
          @result = Binary string to send to decrypt function
HH3C ASCII to Binary converter
HH3C ASCII to Binary converter
def asciitobin(self, cipher=None):
        """
        HH3C ASCII to Binary converter

        Args:
          @cipher = ASCII Ciphertext to convert to binary

        Returns:
          @result = Binary string to send to decrypt function
        """

        if not isinstance(cipher, str):
            raise HH3CError, 'No string sent'

        cipherlen = len(cipher)
        """
        if cipherlen == 24:
            endstep = 16
        elif cipherlen == 88:
            endstep = 64
        else:
        """
        if cipherlen != 24 and cipherlen != 88:
            raise HH3CError, '%s invalid: must be 24 or 88 characters in length but yours is %s.' % (cipher, cipherlen)

        # result is an array of bytes
        result = bytearray()

        # check value starts as ordinal of 'a' (97)
        chkval = ord('a')

        # loop in groups of 4 characters at once.
        for cnt in range(0, cipherlen, 4):
            # -------> character #1
            # get ordinal of first character in group
            cv1 = ord(cipher[cnt])

            if cv1 == chkval:
                # ordinals are the same, set checkval 63
                cv1 = ord('?')

            # move cv1 to cv2 and subtract 33
            cv2 = cv1-33

            # -------> character #2
            # get the ordinal of the next character
            cv1 = ord(cipher[cnt+1])

            if cv1 != chkval:
                # ordinals are not the same, shift cv2 left 6 bytes
                cv2 = cv2 << 6
            else:
                # ordinals are the same, set checkval to 63
                cv1 = ord('?')

            # move cv1 to cv2 and subtract 33
            cv1 = cv1-33
            # or cv2 and cv1 together, result into cv2
            cv2 = cv2 | cv1

            # --------> character #3
            # get the ordinal of the 3rd character
            cv1 = ord(cipher[cnt+2])

            if cv1 != chkval:
                # ordinals are not the same, shift cv2 left 6 bytes
                cv2 = cv2 << 6
            else:
                # ordinals are the same, set checkval to 63
                cv1 = ord('?')

            # move cv1 to cv2 and subtract 33
            cv1 = cv1-33
            # or cv2 and cv1 together, result into cv2
            cv2 = cv2 | cv1

            # --------> character #4
            # get the ordinal of the 4th character
            cv1 = ord(cipher[cnt+3])
            if cv1 != chkval:
                # ordinals are not the same, shift cv2 left 6 bytes
                cv2 = cv2 << 6
            else:
                # ordinals are the same, set checkval to 63
                cv1 = ord('?')

            # output
            cv1 = cv1-33
            cv2 = cv2 | cv1

            # take ordinal result and cut byte values into result
            result.append((cv2 & 0xff0000) >> 16)
            result.append((cv2 & 0xff00) >> 8)
            result.append(cv2 & 0xff)

            #print str(result).encode("hex")

        return result
def asciitobin ( self , cipher = None ) : if not isinstance ( cipher , str ) : raise HH3CError , 'No string sent' cipherlen = len ( cipher ) """
        if cipherlen == 24:
            endstep = 16
        elif cipherlen == 88:
            endstep = 64
        else:
        """ if cipherlen != 24 and cipherlen != 88 : raise HH3CError , '%s invalid: must be 24 or 88 characters in length but yours is %s.' % ( cipher , cipherlen ) # result is an array of bytes result = bytearray ( ) # check value starts as ordinal of 'a' (97) chkval = ord ( 'a' ) # loop in groups of 4 characters at once. for cnt in range ( 0 , cipherlen , 4 ) : # -------> character #1 # get ordinal of first character in group cv1 = ord ( cipher [ cnt ] ) if cv1 == chkval : # ordinals are the same, set checkval 63 cv1 = ord ( '?' ) # move cv1 to cv2 and subtract 33 cv2 = cv1 - 33 # -------> character #2 # get the ordinal of the next character cv1 = ord ( cipher [ cnt + 1 ] ) if cv1 != chkval : # ordinals are not the same, shift cv2 left 6 bytes cv2 = cv2 << 6 else : # ordinals are the same, set checkval to 63 cv1 = ord ( '?' ) # move cv1 to cv2 and subtract 33 cv1 = cv1 - 33 # or cv2 and cv1 together, result into cv2 cv2 = cv2 | cv1 # --------> character #3 # get the ordinal of the 3rd character cv1 = ord ( cipher [ cnt + 2 ] ) if cv1 != chkval : # ordinals are not the same, shift cv2 left 6 bytes cv2 = cv2 << 6 else : # ordinals are the same, set checkval to 63 cv1 = ord ( '?' ) # move cv1 to cv2 and subtract 33 cv1 = cv1 - 33 # or cv2 and cv1 together, result into cv2 cv2 = cv2 | cv1 # --------> character #4 # get the ordinal of the 4th character cv1 = ord ( cipher [ cnt + 3 ] ) if cv1 != chkval : # ordinals are not the same, shift cv2 left 6 bytes cv2 = cv2 << 6 else : # ordinals are the same, set checkval to 63 cv1 = ord ( '?' ) # output cv1 = cv1 - 33 cv2 = cv2 | cv1 # take ordinal result and cut byte values into result result . append ( ( cv2 & 0xff0000 ) >> 16 ) result . append ( ( cv2 & 0xff00 ) >> 8 ) result . append ( cv2 & 0xff ) #print str(result).encode("hex") return result