Python Forensics 简明教程
Python Forensics - Cracking an Encryption
在本章中,我们将了解如何在分析和证据期间破解提取的文本数据。
密码学中的纯文本是一些正常的可读文本,例如一条消息。另一方面,密文是由输入纯文本后提取的加密算法的输出。
我们将明文消息转换为密文消息的简单算法是 Caesar cipher ,这是 Julius Caesar 发明的,用于向他的敌人保密明文。此密码涉及将消息中的每个字母在字母表中向前移动三个位置。
以下是一个演示说明。
a → D
b → E
c → F
w → Z
x → A
y → B
z → C
Example
A message entered when you run a Python script gives all the possibilities of characters, which is used for pattern evidence.
The types of pattern evidences used are as follows −
-
Tire Tracks and Marks
-
Impressions
-
Fingerprints
Every biometric data comprises of vector data, which we need to crack to gather full-proof evidence.
The following Python code shows how you can produce a cipher text from plain text −
import sys
def decrypt(k,cipher):
plaintext = ''
for each in cipher:
p = (ord(each)-k) % 126
if p < 32:
p+=95
plaintext += chr(p)
print plaintext
def main(argv):
if (len(sys.argv) != 1):
sys.exit('Usage: cracking.py')
cipher = raw_input('Enter message: ')
for i in range(1,95,1):
decrypt(i,cipher)
if __name__ == "__main__":
main(sys.argv[1:])