the Vigenère cipher

the Vigenère cipher is considered one of the oldest encryption methods,
the main idea of this encryption is to shift the letters within calculated places.
Encryption The plaintext(P) and key(K) are added modulo 26. Ei = (Pi + Ki) mod 26 |
and you can perform it like this using python programming language
""" Subject : CRYPTOGRAPHIC METHODS OF INFORMATIONAL SAFETY. Laboratory work: 1 Topic: CRYPTOGRAPHY AND ENCRYPTION. Conducted by: Nawras Bukhari. Group: СИБа 19-7. Supervisor: Naubeto Daulet Abatuly. """ # шифрлау кілтін жасау def generateKey(string, key): # кілт пен жолдың мәнін анықтау || Defining the string and key variables key = list(key) if len(string) == len( key): # егер жолдың ұзындығы кілттің ұзындығына тең болса || if the length of string equals length of key return key # кілт мәнін қайтару (басып шығару). || return the value of key else: # Егер болмаса || If not for i in range(len(string) - len(key)): # I мәніне сәйкес цикл key.append(key[i % len(key)]) # тізімде пішімдеу return "".join(key) def cipherText(string, key): cipher_text = [] for i in range(len(string)): x = (ord(string[i]) + ord(key[i])) % 26 x += ord('A') cipher_text.append(chr(x)) return "".join(cipher_text) def originalText(cipher_text, key): orig_text = [] for i in range(len(cipher_text)): x = (ord(cipher_text[i]) - ord(key[i]) + 26) % 26 x += ord('A') orig_text.append(chr(x)) return "".join(orig_text) if __name__ == "__main__": string = "THISISASECRETMESSAGEWHICHIWILLENCRYPT" # біз шифрлағымыз келетін мәтін keyword = "MYUNCLESNAMEISGEORGEMYUNCLESNAMEISGEO" # шифрлау кілті key = generateKey(string, keyword) cipher_text = cipherText(string, key) print("Encrypted text :", cipher_text) print("Original/Decrypted Text :", originalText(cipher_text, key)) |
Share :
Add New Comment