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

Function generate_key

ciphers/beaufort_cipher.py:14–28  ·  view source on GitHub ↗

>>> generate_key("THE GERMAN ATTACK","SECRET") 'SECRETSECRETSECRE'

(message: str, key: str)

Source from the content-addressed store, hash-verified

12# a cyclic manner until it's length isn't
13# equal to the length of original text
14def generate_key(message: str, key: str) -> str:
15 """
16 >>> generate_key("THE GERMAN ATTACK","SECRET")
17 'SECRETSECRETSECRE'
18 """
19 x = len(message)
20 i = 0
21 while True:
22 if x == i:
23 i = 0
24 if len(key) == len(message):
25 break
26 key += key[i]
27 i += 1
28 return key
29
30
31# This function returns the encrypted text

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected