Ejemplo n.º 1
0
    def _crypt(self, msg):
        assert(type(msg) == type("hello"))
        """
        _crypt, takes a cipher text/plain text and decrypts/encrypts it.
        INPUT:
            msg, either Plain Text or Cipher Text.
        OUTPUT:
            new_msg, if PT, then output is CT and vice-versa.
        """
        # ======== IMPLEMENTATION GOES HERE =========
        
        new_msg=""
        new_msg_array=[]
        #Iterate the bytearray of the msg
        for byte in bytearray(msg):
            
            #For every byte perform the encipher/decipher function
            newByte=byte^auxillary.msb(self.r_i)
            #Update the register
            self.updateShiftRegister()
            #Append the new byte to the new message array
            new_msg_array.append(newByte)

        #Turn the new_msg_array into a byte array
        new_msg_array=bytearray(new_msg_array)

        new_msg=str(new_msg_array)		

        # ======== END IMPLEMENTATION ===============
        return new_msg
Ejemplo n.º 2
0
 def _crypt(self, msg):
     """
     _crypt, takes a cipher text/plain text and decrypts/encrypts it.
     INPUT:
         msg, either Plain Text or Cipher Text.
     OUTPUT:
         new_msg, if PT, then output is CT and vice-versa.
     """
     # ======== IMPLEMENTATION GOES HERE =========
     #msgarray should store the msg as byte array.
     msgarray = bytearray()
     msgarray = bytearray(msg)
     # enumerate byte by byte with XOR
     for count, elem in enumerate(msgarray):
         #store the byte after XOR operation
         msgarray[count] = elem^auxillary.msb(self.r_i)
         #update the the register.
         self.updateShiftRegister()
         pass
     # ======== END IMPLEMENTATION ===============
     return msgarray