We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8d47354 commit 7754262Copy full SHA for 7754262
programming/python/random_hash.py
@@ -13,7 +13,7 @@
13
is_py3 = sys.version_info >= (3, ) # XXX: use six package instead.
14
if is_py3:
15
CHR_MAX = 0x10FFFF
16
- CONV_FUNC = lambda x: str(chr(x))
+ CONV_FUNC = lambda x: chr(x).encode()
17
else:
18
CHR_MAX = 128
19
CONV_FUNC = lambda x: chr(x)
@@ -45,12 +45,9 @@ def main():
45
random.seed()
46
47
m = hashlib.sha512()
48
- rand_str = "".join([
49
- CONV_FUNC(random.randrange(CHR_MAX - 1))
50
- for _ in range(args.length)
51
- ])
52
- if is_py3: # use six
53
- rand_str = rand_str.encode("utf-8")
+ rand_str = b"".join(
+ CONV_FUNC(random.randrange(CHR_MAX - 1)) for _ in range(args.length)
+ )
54
55
m.update(rand_str)
56
# NB: python 2.x doesn't support `.hexdigest(length)`
0 commit comments