MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / vernam_encrypt

Function vernam_encrypt

ciphers/vernam_cipher.py:1–12  ·  view source on GitHub ↗

>>> vernam_encrypt("HELLO","KEY") 'RIJVS'

(plaintext: str, key: str)

Source from the content-addressed store, hash-verified

1def vernam_encrypt(plaintext: str, key: str) -> str:
2 """
3 >>> vernam_encrypt("HELLO","KEY")
4 'RIJVS'
5 """
6 ciphertext = ""
7 for i in range(len(plaintext)):
8 ct = ord(key[i % len(key)]) - 65 + ord(plaintext[i]) - 65
9 while ct > 25:
10 ct = ct - 26
11 ciphertext += chr(65 + ct)
12 return ciphertext
13
14
15def vernam_decrypt(ciphertext: str, key: str) -> str:

Callers 1

vernam_cipher.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected