一、 维吉利亚(Vigenere)密码
1、加密原理:
26个小写英文字母(a-z)对应26个自然数(0-25),也就是a对应0,b对应1,c对应2,以此类推。
2、加密方法:
假设明文信息是abcd,密码是ab,那么加密后的密文(对应的数字)=明文(对应的数字)+密码(对应的数字)。
①明文abcd有四位,密码ab两位。因此要加密就得补上空余的位置。如果明文是abcde,那么对应填补上的密码就会是ababa。
②明文第一位是a,对应0;密码第一位是a,对应0;所以得到的密文第一位就是a,因为0+0=0,0对应的是a。
③明文第二位是b,对应1;密码第一位是b,对应1;所以得到的密文第一位就是b,因为1+1=2,2对应的是c。
④所以最后的密文会等于:acce。
3、破解方法:
做一个减法,密文减去明文。
二、python的学习——错误处理
## Example 1
try:
a = int(input("Enter a:"))
b = int(input("Enter b:"))
c = a/b
print(c)
except:
print("Can't divide with zero")
## Example 2
try:
#this will throw an exception if the file doesn't exist.
fileptr = open("file.txt","r")
except IOError:
print("File not found")
else:
print("The file opened successfully")
fileptr.close()
## Example 3
try:
fptr = open("data.txt",'r')
try:
fptr.write("Hello World!")
finally:
fptr.close()
print("File Closed")
except:
print("Error")