def test_feistel(L_00, L_10): """Test to see if a 2-stage feistel network was used for DES-like encryption >>> L2_00 = ('5f67abaf', '7b50baab', '290b6e3a', '39155d6f') >>> L2_10 = ('bbe033c0', 'ac343a22', 'd6f491c5', 'eea6e3dd') >>> [test_feistel(L2a, L2b) for (L2a, L2b) in zip(L2_00, L2_10)] ['unk', 'unk', 'INSECURE', 'unk'] """ L_xor = hexxor(L_00, L_10) if all(c == L_xor[(i + 1) % len(L_xor)] for i, c in enumerate(L_xor)): return 'INSECURE' return 'unk'
def test_feistel(L_00, L_10): """Test to see if a 2-stage feistel network was used for DES-like encryption >>> L2_00 = ('5f67abaf', '7b50baab', '290b6e3a', '39155d6f') >>> L2_10 = ('bbe033c0', 'ac343a22', 'd6f491c5', 'eea6e3dd') >>> [test_feistel(L2a, L2b) for (L2a, L2b) in zip(L2_00, L2_10)] ['unk', 'unk', 'INSECURE', 'unk'] """ L_xor = hexxor(L_00, L_10) if all(c==L_xor[(i+1)%len(L_xor)] for i, c in enumerate(L_xor)): return 'INSECURE' return 'unk'
def f2(x, y, hex=True): if hex: return hexxor(E(x, x), y)
def f1(x, y, hex=True): if hex: return hexxor(E(y, x), y)