def test_append_nothing_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(prepend=False)
        node.add_attr(model.StringListAttr(strings=['A', 'B']))
        node.add_attr(model.NothingAdderAttr())
        chain.add_node(node)
        
        truth_words = ['heLlo', 'heLloA', 'heLloB', 'worLd', 'worLdA', 'worLdB']
        result = list(chain.get_words())
        self.assertEqual(sorted(result), sorted(truth_words))
        self.assertEqual(len(result), chain.count_words())
    
        rules = chain.get_rules()
        self.assert_hashcat_result(truth_words, rules, basewords)
        self.assertTrue(chain.check_hashcat_compatible())
        rules_truth = '''$A
$B
:
'''
        self.assertEqual(rules_truth, rules)
 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_substitution_hashcat_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.MutateNode()
     attr = model.SubstitutionAttr(type_='All', checked_vals=['l -> i', 'o -> 0'], all_together=True)
     node.add_attr(attr)
     chain.add_node(node)
     
     truth_words = ['heii0', 'w0rid']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     # Substitution counts are over-estimated due to de-duplication
     self.assertEqual(2, chain.count_words())
     # Byte counts for multi-character replacements are estimated as if
     # they were single-character
     self.assertEqual(12, chain.count_bytes())
     self.assertTrue(chain.check_hashcat_compatible())
 
     rules = chain.get_rules()
     self.assert_hashcat_result(truth_words, rules, basewords)
     self.assertTrue(chain.check_hashcat_compatible())
     self.assertEqual('sliso0\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_add_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(prepend=False)
        node.add_attr(model.FileAttr(path=self.test_words_path))
        chain.add_node(node)
        
        node = model.AddNode(prepend=False)
        node.add_attr(model.StringListAttr(strings=['A', 'B']))
        node.add_attr(model.NothingAdderAttr())
        chain.add_node(node)
        
        truth_words = ['heLlotest1A', 'heLlotest1B', 'heLlotest1', 'heLlotest word 2A', 'heLlotest word 2B', 'heLlotest word 2', 'heLloTHIRDTESTWORDA', 'heLloTHIRDTESTWORDB', 'heLloTHIRDTESTWORD', 'worLdtest1A', 'worLdtest1B', 'worLdtest1', 'worLdtest word 2A', 'worLdtest word 2B', 'worLdtest word 2', 'worLdTHIRDTESTWORDA', 'worLdTHIRDTESTWORDB', 'worLdTHIRDTESTWORD']
        result = list(chain.get_words())
        self.assertEqual(sorted(result), sorted(truth_words))
        self.assertEqual(len(result), chain.count_words())
    
        rules = chain.get_rules()
        self.assert_hashcat_result(truth_words, rules, basewords)
        self.assertTrue(chain.check_hashcat_compatible())
    
        rules_truth = '''$t$e$s$t$1$A
$t$e$s$t$ $w$o$r$d$ $2$A
$T$H$I$R$D$T$E$S$T$W$O$R$D$A
$t$e$s$t$1$B
$t$e$s$t$ $w$o$r$d$ $2$B
$T$H$I$R$D$T$E$S$T$W$O$R$D$B
$t$e$s$t$1:
$t$e$s$t$ $w$o$r$d$ $2:
$T$H$I$R$D$T$E$S$T$W$O$R$D:
'''
        self.assertEqual(rules_truth, rules)
 def test_empty_mutate_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.MutateNode()
     chain.add_node(node)
     
     result = list(chain.get_words())
     self.assertEqual(sorted(basewords), 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(basewords), rules, basewords=basewords)
     self.assertTrue(chain.check_hashcat_compatible())
 
     self.assertEqual(':\n', rules)
 def test_substitution_mutator_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.MutateNode()
     attr = model.SubstitutionAttr(type_='First', checked_vals=['l -> i', 'l -> 1'], all_together=False)
     node.add_attr(attr)
     chain.add_node(node)
     
     truth_words = ['he1lo', 'heilo', 'wor1d', 'worid']
     result = list(chain.get_words())
     self.assertEqual(sorted(truth_words), sorted(result))
     # Substitution counts are over-estimated due to de-duplication
     self.assertEqual(2, chain.count_words())
     # Byte counts for multi-character replacements are estimated as if
     # they were single-character
     self.assertEqual(16, chain.count_bytes())
     self.assertFalse(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)
 def test_stringlist_attr(self):
     attr = model.StringListAttr(strings=self.test_words)
     
     result = list(attr.get_words())
     self.assertEqual(self.test_words, result)
     self.assertEqual(len(result), attr.count_words(0))