implement encrypt in vig.py

This commit is contained in:
2020-11-22 04:56:40 +01:00
parent f7f35adfa0
commit 723b2bbf66

View File

@@ -1,3 +1,15 @@
def encrypt(key, plaintext):
pln_bytes = bytes(plaintext, 'UTF-8')
key_bytes = bytes(key, 'UTF-8')
out=""
for i in range(len(pln_bytes)):
pln_chr_index = pln_bytes[i] - 0x61
key_chr_index = key_bytes[i % len(key)] - 0x61
out_chr_index = (pln_chr_index + key_chr_index) % 26
out = out + chr(out_chr_index + 0x61)
return out
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
@@ -9,3 +21,4 @@ if __name__ == "__main__":
args = parser.parse_args()
print(encrypt("bbb", "test"))