python - How can I make a python encryption and decryption program with my own criptgraphy?
问题描述
The criptogrphy looks like this:
a = "v07u4tLKinfa"
b = "zz45tTn8u4o0"
c = "W46tEr10d01z"
d = "5aPSCr36quA7"
e = "Zg6pPrg17t15"
f = "Po84cr3Ud25M"
g = "L0l1crXtOO11"
h = "7G1CaZ2wBg9f"
i = "Z1Yd84we71y3"
j = "LL6TRe0yR4tj"
k = "kt426ug76Vz3"
l = "26IzOZyrXCt4"
m = "Z3uj09HJ6Iou"
n = "0d2Wna13lERT"
o = "N935efQef3JH"
p = "7j43Ghnf6R4o"
q = "dF13Rw9nX6i8"
r = "DOu3fw073r81"
s = "3C0w23rTg5Ij"
t = "TE436nyWi5ee"
u = "58Ybt78n3e06"
v = "39j8rH9TYrcO"
w = "0NAtO48veQM7"
x = "K2uC2tgEVBn4"
y = "9nRm03iH8ECn"
z = "8brYHI304ld2"
I want the program to encrypt a plain text like (" this ") by changing each letter.
example: ("this") changes to ("TE436nyWi5ee7G1CaZ2wBg9fZ1Yd84we71y33C0w23rTg5Ij")
note: I also want the text to be user input.
解决方案
首先,您将映射放入字典中:
cipher = {
'a': "v07u4tLKinfa",
'b': "zz45tTn8u4o0",
'c': "W46tEr10d01z",
'd': "5aPSCr36quA7",
'e': "Zg6pPrg17t15",
'f': "Po84cr3Ud25M",
'g': "L0l1crXtOO11",
'h': "7G1CaZ2wBg9f",
'i': "Z1Yd84we71y3",
'j': "LL6TRe0yR4tj",
'k': "kt426ug76Vz3",
'l': "26IzOZyrXCt4",
'm': "Z3uj09HJ6Iou",
'n': "0d2Wna13lERT",
'o': "N935efQef3JH",
'p': "7j43Ghnf6R4o",
'q': "dF13Rw9nX6i8",
'r': "DOu3fw073r81",
's': "3C0w23rTg5Ij",
't': "TE436nyWi5ee",
'u': "58Ybt78n3e06",
'v': "39j8rH9TYrcO",
'w': "0NAtO48veQM7",
'x': "K2uC2tgEVBn4",
'y': "9nRm03iH8ECn",
'z': "8brYHI304ld2"
}
然后你可以用这种方式“加密”一个字符串:
>>> s = 'this'
>>> ' '.join(cipher[c] for c in s)
'TE436nyWi5ee 7G1CaZ2wBg9f Z1Yd84we71y3 3C0w23rTg5Ij'
为了解密,构建 的逆映射cipher
:
reverse_cipher = {v: k for k, v in cipher.items()}
并以这种方式“解密”:
>>> sc = 'TE436nyWi5ee 7G1CaZ2wBg9f Z1Yd84we71y3 3C0w23rTg5Ij'
>>> ''.join(reverse_cipher[x] for x in sc.split())
'this'
完成这个学习实验后,如果你真的想做加密,千万不要自己做,使用现有的库。
这种替换密码很容易被破解。