def test_parallel_mutator_chain(self):
     chain = model.Chain()
     
     node = model.BaseNode(is_root=True)
     attr = model.FileAttr(path=self.test_words_path)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     
     attr = model.CaseAttr(type_='First', case='Uppercase')
     node.add_attr(attr)
     attr = model.CaseAttr(type_='Toggle', idx=3)
     node.add_attr(attr)
     
     chain.add_node(node)
     
     truth_words = ['Test1', 'tesT1',
                    'Test word 2', 'tesT word 2',
                    'THIrDTESTWORD', 'Thirdtestword']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     self.assertEqual(6, chain.count_words())
     self.assertEqual(64, chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
 def test_case_mutator_attr(self):
     attr = model.CaseAttr(type_='First', case='Uppercase')
     result = list(attr.get_words(['test1', 'test2']))
     self.assertEqual(result, ['Test1', 'Test2'])
     self.assertEqual(len(result), attr.count_words(2))
     
     attr = model.CaseAttr(type_='All', case='Uppercase')
     result = list(attr.get_words(['test1', 'test2']))
     self.assertEqual(result, ['TEST1', 'TEST2'])
     self.assertEqual(len(result), attr.count_words(2))
     
     attr = model.CaseAttr(type_='First', case='Lowercase')
     result = list(attr.get_words(['TEST1', 'TEST2']))
     self.assertEqual(result, ['tEST1', 'tEST2'])
     self.assertEqual(len(result), attr.count_words(2))
     
     attr = model.CaseAttr(type_='Toggle', idx=3)
     result = list(attr.get_words(['test1', 'test2']))
     self.assertEqual(result, ['tesT1', 'tesT2'])
     self.assertEqual(len(result), attr.count_words(2))
     
     attr = model.CaseAttr(type_='Toggle', idx=3)
     result = list(attr.get_words(['', 'test2']))
     self.assertEqual(result, ['', 'tesT2'])
     self.assertEqual(len(result), attr.count_words(2))
 def test_empty_add_case_chain(self):
     chain = model.Chain()
     
     basewords = ['hello', 'world']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=basewords)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.AddNode()
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     attr = model.CaseAttr(type_='First', case='Uppercase')
     node.add_attr(attr)
     chain.add_node(node)
     
     truth_words = ['Hello', 'World']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     self.assertEqual(len(basewords), chain.count_words())
     self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
     
     rules = chain.get_rules()
     self.assert_hashcat_result(sorted(truth_words), rules, basewords=basewords)
     self.assertTrue(chain.check_hashcat_compatible())
 
     self.assertEqual(':c\n', rules)
 def test_nothing_mutator_chain(self):
     chain = model.Chain()
     
     node = model.BaseNode(is_root=True)
     attr = model.FileAttr(path=self.test_words_path)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     
     attr = model.CaseAttr(type_='First', case='Uppercase')
     node.add_attr(attr)
     attr = model.NothingMutatorAttr()
     node.add_attr(attr)
     
     chain.add_node(node)
     
     truth_words = ['Test1', 'test1',
                    'Test word 2', 'test word 2',
                    'THIRDTESTWORD', 'Thirdtestword']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     self.assertEqual(6, chain.count_words())
     self.assertEqual(64, chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
 
     rules = chain.get_rules()
     self.assert_hashcat_result(truth_words, rules)
     self.assertTrue('c\n:\n', rules)
 def test_long_hashcat_chain(self):
     chain = model.Chain()
     
     strings = ['heLlo', 'worLd']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=strings)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     node.add_attr(model.CaseAttr(type_='First', case='Uppercase'))
 def test_serial_mutator_chain(self):
     chain = model.Chain()
     
     node = model.BaseNode(is_root=True)
     attr = model.FileAttr(path=self.test_words_path)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     attr = model.CaseAttr(type_='First', case='Uppercase')
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     attr = model.CaseAttr(type_='Toggle', idx=3)
     node.add_attr(attr)
     chain.add_node(node)
     
     truth_words = ['TesT1', 'TesT word 2', 'ThiRdtestword']
     result = list(chain.get_words())
     self.assertEqual(truth_words, result)
     self.assertEqual(len(result), chain.count_words())
     self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
 def test_case_hashcat_chain(self):
     chain = model.Chain()
     
     strings = ['heLlo', 'worLd', 'hi']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=strings)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     node.add_attr(model.CaseAttr(type_='Toggle', idx=3))
     chain.add_node(node)
     
     truth_words = ['heLLo', 'hi', 'world']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(set(result)))
     #self.assertEqual(9, chain.count_words())
     #self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
 
     rules = chain.get_rules()
     self.assert_hashcat_result(truth_words, rules, basewords=strings)
     self.assertTrue(chain.check_hashcat_compatible())
     self.assertEqual('T3\n', rules)
     self.assertEqual(len(result), chain.count_words())
     self.assertEqual(len('\n'.join(result)+'\n'), chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
 
 def test_long_hashcat_chain(self):
     chain = model.Chain()
     
     strings = ['heLlo', 'worLd']
     node = model.BaseNode(is_root=True)
     attr = model.StringListAttr(strings=strings)
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.MutateNode(is_case=True)
     node.add_attr(model.CaseAttr(type_='First', case='Uppercase'))
     node.add_attr(model.CaseAttr(type_='All', case='Lowercase'))
     node.add_attr(model.NothingMutatorAttr())
     chain.add_node(node)
     
     node = model.MutateNode()
     attr = model.SubstitutionAttr(type_='All', checked_vals=['l -> i', 'l -> 1', 'd -> b'], all_together=False)
     #node.add_attr(model.NothingMutatorAttr()) # differs from hashcat when this is missing
     node.add_attr(attr)
     chain.add_node(node)
     
     node = model.AddNode()
     node.add_attr(model.RangeAttr(0, 3))
     chain.add_node(node)
     
     truth_words = [#'Hello', 'heLlo', 'hello', 'World', 'worLd', 'world',
                    'Heiio0', 'heiio0', 'Heiio1', 'heiio1', 'Heiio2', 'heiio2',