def main(): parser = argparse.ArgumentParser(description='Decrypts and authenticates binary content hidden in the lowest bits of a bitmap') parser.add_argument('-k', '--password', type=str, required=True, metavar='<password>', help='The password used for decryption') parser.add_argument('-m', '--macpassword', type=str, required=True, metavar='<macpassword>', help='The password used for authenticity and integrity') parser.add_argument('bitmap', type=file, metavar='<bitmap>', help='The bitmap file to extract the binary file from') args = parser.parse_args() password = args.password macpassword = args.macpassword bitmap = args.bitmap key = int(hashlib.sha256(password).hexdigest(), 16) >> 128 ciphertext = image.show(bitmap) iv = binary.pack(slice(ciphertext, 8)) binary_size = binary.pack(slice(ciphertext, 2)) encrypted = slice(ciphertext, binary_size) decrypted = bytearray(cfb.decrypt(xtea.encrypt, key, iv, encrypted)) mac, decrypted = binary.pack(decrypted[:32]), decrypted[32:] check = int(hmac.new(macpassword, str(decrypted), hashlib.sha256).hexdigest(), 16) if mac == check: for d in decrypted: sys.stdout.write(chr(d)) else: raise Exception('Data has been altered')
def stabilize(self, old, frame, color_frame): # params for ShiTomasi corner detection feature_params = dict(maxCorners=100, qualityLevel=0.3, minDistance=7, blockSize=7) # Parameters for lucas kanade optical flow lk_params = dict(winSize=(15, 15), maxLevel=2, criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03)) hsv = np.zeros_like(frame) # prev = cv2.cvtColor(old, cv2.COLOR_BGR2GRAY) prev = old p0 = cv2.goodFeaturesToTrack(prev, mask=None, **feature_params) # next = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) next = frame # d = np.ones(3)*4e-3 # n = np.ones(3)*0.25 try: # calculate optical flow p1, st, _ = cv2.calcOpticalFlowPyrLK(prev, next, p0, None, **lk_params) # Select good points good_new = p1[st == 1] good_old = p0[st == 1] # print 'Good points old :-\n',good_old # print 'Good points new :-\n',good_new # Get transformation matrix from the optical flow transform = cv2.findHomography(good_old, good_new) TRANS_ACC.append(transform[0]) len_trans = len(TRANS_ACC) # print len_trans,'\n\n' # print deque(slice(TRANS_ACC,1, len_trans)) # value1 = deque(slice(TRANS_ACC,1, len_trans))-deque(slice(TRANS_ACC,0, len_trans-1)) TRANS_DIFF = deque(slice(TRANS_ACC, 1, len_trans)) - deque( slice(TRANS_ACC, 0, len_trans - 1)) if len_trans > 2 else np.zeros(shape=( 3, 3 )) if len_trans == 1 else TRANS_ACC[1] - TRANS_ACC[0] transform_mean = sum(TRANS_ACC) / len_trans #print transform_mean except: transform = np.eye(3) #np.zeros(shape=(3,3)) #print('<4 Good points found') try: result = cv2.warpPerspective(color_frame, transform_mean, (frame.shape[1], frame.shape[0])) except Exception as e: #print('wrap failed due to <4 Good points found. No worries') result = color_frame return result
def setHistorySize(self, size): if (size < 0): return size_old = len(self.__outputHist) if size_old < size: tmp = (size - size_old) * [0] self.__outputHist.extend(tmp) self.__errorHist.extend(tmp) self.__timeHist.extend(tmp) elif size_old > size: self.__outputHist = deque( itertools.slice(self.__outputHist, 0, size)) self.__errorHist = deque( itertools.slice(self.__outputHist, 0, size)) self.timetHist = deque(itertools.slice(self.__outputHist, 0, size)) self.__histSize = size
def _get_chunks(*iterables, chunksize): """分块迭代一个可调用对象""" it = zip(*iterables) while True: chunk = tuple(itertools.slice(it, chunksize)) if not chunk: return yield chunk
def chunked(it, n): """ From http://stackoverflow.com/a/8991553 """ it = iter(it) while True: chunk = tuple(slice(it, n)) if not chunk: return yield chunk
def roundrobin(*iterables): "roundrobin('ABC', 'D', 'EF') --> A D E B F C" # Recipe credited to George Sakkis pending = len(iterables) nexts = itertools.cycle(iter(it).next for it in iterables) while pending: try: for next in nexts: yield next() except StopIteration: pending -= 1 nexts = itertools.cycle(itertools.slice(nexts, pending))
import itertools from string import ascii_lowercase x = ''.join(itertools.slice(sample_wr(ascii_lowercase), 50))
def get_some(cursor, N): """ Get at most N items from the cursor, and return as a list """ return [i for i in itertools.slice(cursor, N)]