Skip to content

Commit 6f56b8d

Browse files
author
tp7309
committed
update size estimate accuracy when seperator option applied
1 parent c67ee88 commit 6f56b8d

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
out.dict
33
out.dict.1
44
out.dict.2
5-
README.rst
5+
coverage_html/
66

77
# Byte-compiled / optimized / DLL files
88
__pycache__/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ generated password displayed line by line in `OUTPUT`. It is recommended to use
9696

9797
**[]{m:n:r}**
9898
```
99-
when repeatMode is `?`, [123]{1,2} -> 1 2 3 12 13 21 23 31 32
100-
when repeatMode is `*`, [123]{1,2} -> 1 2 3 11 12 13 21 22 23 31 32 33
99+
when repeatMode is `?`, [123]{1,2:?} -> 1 2 3 12 13 21 23 31 32
100+
when repeatMode is `*`, [123]{1,2:*} -> 1 2 3 11 12 13 21 22 23 31 32 33
101101
```
102102

103103
**[]{m:n}**

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ Repeat mode
132132

133133
::
134134

135-
when repeatMode is `?`, [123]{1,2} -> 1 2 3 12 13 21 23 31 32
136-
when repeatMode is `*`, [123]{1,2} -> 1 2 3 11 12 13 21 22 23 31 32 33
135+
when repeatMode is `?`, [123]{1,2:?} -> 1 2 3 12 13 21 23 31 32
136+
when repeatMode is `*`, [123]{1,2:*} -> 1 2 3 11 12 13 21 22 23 31 32 33
137137

138138
**[]{minLength:maxLength}** default use ``global_repeat_mode`` option.
139139

README_zh_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ Options:
9090

9191
**[]{m:n:r}** 重复m次到n次,重复模式(r)支持`?``*`
9292
```
93-
repeatMode为 `?`, [123]{1,2} -> 1 2 3 12 13 21 23 31 32
94-
repeatMode为 `*`, [123]{1,2} -> 1 2 3 11 12 13 21 22 23 31 32 33
93+
repeatMode为 `?`, [123]{1,2:?} -> 1 2 3 12 13 21 23 31 32
94+
repeatMode为 `*`, [123]{1,2:*} -> 1 2 3 11 12 13 21 22 23 31 32 33
9595
```
9696

9797
**[]{m:n}** 重复m次到n次,重复模式未定义时采用`global_repeat_mode`选项定义的值。

tests/test_TTPassGen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def test_dict_mark_charset_rule(self):
101101

102102
def test_word_seperator(self):
103103
self.assertEquals(go('$0[abc]?', seperator=' '), 1)
104+
self.assertEquals(go('$0[abc]?', seperator='-------------------------\n'), 24)
104105

105106

106107
def test_multi_dict_mark_charset_rule(self):

ttpassgen/ttpassgen.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class DictRule(object):
9797
def __init__(self, order, dictPath):
9898
self.order = order;
9999
self.dictPath = dictPath;
100-
100+
#Rule class end
101101

102102
class WordProductor(object):
103103
def __init__(self, countList, sizeList, productors):
@@ -114,14 +114,13 @@ def prod(cls, iterable):
114114
def totalCount(self):
115115
return self.prod(self.countList)
116116

117-
def totalSize(self):
117+
def totalSize(self, sep=os.linesep):
118118
total = 0
119119
tCount = self.totalCount()
120120
for i, size in enumerate(self.sizeList):
121121
total += size * tCount / self.countList[i]
122-
total += tCount * len(os.linesep)
122+
total += tCount * len(sep)
123123
return total
124-
#Rule class end
125124

126125

127126
def prettySize(size_bytes):
@@ -164,16 +163,19 @@ def getCharsetRuleResultDataSize(rule):
164163
size += count * wordLength
165164
return count, size
166165

166+
167167
def getDictRuleResultDataSize(rule):
168168
sumLines = 0
169+
sepLen = 1
169170
with open(rule.dictPath, 'r') as f:
170171
bufferSize = 1024 * 4
171172
readFunc = f.read #loop optimization
172173
chunk = readFunc(bufferSize)
174+
if '\r\n' in chunk: sepLen = 2
173175
while chunk:
174176
sumLines += chunk.count('\n')
175177
chunk = readFunc(bufferSize)
176-
linSeperatorCount = len(os.linesep) * sumLines
178+
linSeperatorCount = sepLen * sumLines
177179
return sumLines, (os.path.getsize(rule.dictPath) - linSeperatorCount)
178180

179181

@@ -334,7 +336,7 @@ def productCombinationWords(result, rules, dictCacheLimit, partSize, appendMode,
334336
productor = generateWordProductor(rules, dictCacheLimit)
335337
result[1] = int(productor.totalCount())
336338
result[0] = 1
337-
estimatedSize = prettySize(productor.totalSize())
339+
estimatedSize = prettySize(productor.totalSize(sep=seperator))
338340
print(("estimated size: %s, generate dict...")%(estimatedSize))
339341

340342
if not os.path.exists(os.path.abspath(os.path.join(output, os.path.pardir))):
@@ -477,4 +479,4 @@ def cli(mode, dictlist, rule, dict_cache, global_repeat_mode, part_size, append_
477479

478480
if __name__ == "__main__":
479481
cli()
480-
# cli.main(['-d', 'tests/in.dict', '-r', '[?l]{5}', out.dict'])
482+
# cli.main(['-d', '../tests/in.dict', '-r', '[?l]{5}', 'out.dict'])

0 commit comments

Comments
 (0)