feat(all): "cmatrix" avatar imitate "The Matrix"

This commit is contained in:
2023-08-03 16:36:10 +08:00
parent f2ddee0576
commit 334698292d
2 changed files with 292 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
class Vigenere(object):
def __init__(self, key):
assert(type(key) == type("Hello, world!"))
assert(key.isalpha())
self.key = key
self.key = self.key.lower()
self.key_len = len(key)
self.chr2num = {}
for i in range(26):
self.chr2num[chr(ord('a')+i)] = i
print(self.chr2num)
def encrypt(self, plaintext):
assert(type(plaintext) == type("Hello, world!"))
assert(plaintext.isalpha())
plaintext = plaintext.lower()
ciphertext = ""
for i in range(0, len(plaintext), self.key_len):
for j in range(self.key_len):
tmp = i + j
if tmp < len(plaintext):
ciphertext += chr((self.chr2num[plaintext[tmp]] + self.chr2num[self.key[j]]) % 26 + ord('a'))
else:
break
print(ciphertext)
if __name__ == "__main__":
v = Vigenere("tvtsidl")
v1 = Vigenere("tvtddfm")