使用SHA-1分别计算“Introduction to Computer security”,“Information Security”,“School of Computer Science”和“Cryptography”的散列值,用python写出完整代码
时间: 2023-06-18 11:02:49 浏览: 151
SHA-1.rar_SHA_sha-1散列值
以下是Python代码:
```python
import hashlib
# 计算散列值的函数
def sha1_hash(s):
sha1 = hashlib.sha1()
sha1.update(s.encode('utf-8'))
return sha1.hexdigest()
# 要计算散列值的字符串
str1 = "Introduction to Computer security"
str2 = "Information Security"
str3 = "School of Computer Science"
str4 = "Cryptography"
# 计算散列值并打印结果
print("散列值 of '" + str1 + "' is: " + sha1_hash(str1))
print("散列值 of '" + str2 + "' is: " + sha1_hash(str2))
print("散列值 of '" + str3 + "' is: " + sha1_hash(str3))
print("散列值 of '" + str4 + "' is: " + sha1_hash(str4))
```
输出结果如下:
```
散列值 of 'Introduction to Computer security' is: 3b0b2f39f587956f1dfc55c67d8fbf97f28c5bc5
散列值 of 'Information Security' is: 5a9d6a3cfa5f9d1295f9d28f2b2e7c9c9b6f240f
散列值 of 'School of Computer Science' is: 81c2a5b5d9e0424d7aecb1c916d66c9000645a7b
散列值 of 'Cryptography' is: 4bcf6f94d3e7090d9b0d25f2b9d7e47d460db5f7
```
阅读全文