We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 782e19d commit 49c7aa4Copy full SHA for 49c7aa4
1 file changed
xyjxyf/show_me_the_code.py
@@ -488,6 +488,24 @@ def statistics_month_time():
488
return dic
489
490
491
+# 第 0021 题: 请使用 Python 对密码加密
492
+from hashlib import sha256
493
+from hmac import HMAC
494
+
495
+def encrypt_password(password, salt=None):
496
+ if salt is None:
497
+ salt = os.urandom(8)
498
499
+ if isinstance(password, str):
500
+ password = password.encode('UTF-8')
501
502
+ ret = password
503
+ for i in range(10):
504
+ ret = HMAC(ret, salt, sha256).digest()
505
506
+ return salt + ret
507
508
509
# 第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用
510
511
@@ -590,9 +608,10 @@ def statistics_month_time():
590
608
# break
591
609
592
610
# 0020
593
- statistics_month_time()
611
+ # statistics_month_time()
594
612
595
613
# 0021
614
+ encrypt_password("123")
596
615
597
616
# 0022
598
617
0 commit comments