def test2(): outedges,walldomains,varsaffectedatwall=tc.test2() wallinfo = wl.makeWallInfo(outedges,walldomains,varsaffectedatwall) print set(wallinfo[(0,1)])==set([(3,('um',)),(4,('um',))]) print wallinfo[(3,2)]==[(0,('dM',))] print wallinfo[(5,2)]==[(0,('dM',))] print wallinfo[(1,4)]==[(6,('uu',))]
def test2(): outedges, walldomains, varsaffectedatwall = tc.test2() wallinfo = wl.makeWallInfo(outedges, walldomains, varsaffectedatwall) print set(wallinfo[(0, 1)]) == set([(3, ('um', )), (4, ('um', ))]) print wallinfo[(3, 2)] == [(0, ('dM', ))] print wallinfo[(5, 2)] == [(0, ('dM', ))] print wallinfo[(1, 4)] == [(6, ('uu', ))]
def test2(showme=1, findallmatches=1): wallinfo = makeWallInfo(*tc.test2()) pattern = ['dM', 'md', 'um', 'Mu', 'dM'] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(2, 0, 1, 3, 2), (2, 0, 1, 4, 6, 5, 2)]) if showme and not findallmatches: print match[0] in [(2, 0, 1, 3, 2), (2, 0, 1, 4, 6, 5, 2)] pattern = ['Mu', 'dM', 'md', 'um', 'Mu'] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(3, 2, 0, 1, 3), (6, 5, 2, 0, 1, 4, 6)]) if showme and not findallmatches: print match[0] in [(3, 2, 0, 1, 3), (6, 5, 2, 0, 1, 4, 6)] pattern = ['um', 'Mu'] #acyclic match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(1, 4, 6), (1, 3)]) if showme and not findallmatches: print match[0] in [(1, 4, 6), (1, 3)]
def test2(showme=1, findallmatches=1): wallinfo = makeWallInfo(*tc.test2()) pattern = ["dM", "md", "um", "Mu", "dM"] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(2, 0, 1, 3, 2), (2, 0, 1, 4, 6, 5, 2)]) if showme and not findallmatches: print match[0] in [(2, 0, 1, 3, 2), (2, 0, 1, 4, 6, 5, 2)] pattern = ["Mu", "dM", "md", "um", "Mu"] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(3, 2, 0, 1, 3), (6, 5, 2, 0, 1, 4, 6)]) if showme and not findallmatches: print match[0] in [(3, 2, 0, 1, 3), (6, 5, 2, 0, 1, 4, 6)] pattern = ["um", "Mu"] # acyclic match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(1, 4, 6), (1, 3)]) if showme and not findallmatches: print match[0] in [(1, 4, 6), (1, 3)]
def blockify(input_bin_str, block_len): return [ input_bin_str[i:i + block_len] for i in range(0, len(input_bin_str), block_len) ] def cbc_decrypt(cipher, input_bin_str, iv, block_len): # Function for decrypting a single block def decrypt_block(cipher, enc_str, iv): return strxor(cipher.decrypt(enc_str), iv) output_str = "" block_list = blockify(input_bin_str, block_len) next_iv = iv for block in block_list: output_str += decrypt_block(cipher, block, next_iv) next_iv = block return output_str if __name__ == "__main__": testcases.test1() testcases.test2() testcases.test3() testcases.test4() testcases.test5a() testcases.test5b()