Off-Plataform Project: Coded Correspondence All steps

Here’s my code for this project. Hope it can helps

alphabet = “abcdefghijklmnopqrstuvwxyz”
def cryptography(sentence, offset):
decoded_sentence = ‘’
for letter in sentence:
if letter.lower() in alphabet:
position = alphabet.find(letter)
new_position = (position + offset) % 26
decoded_sentence += alphabet[new_position]
else:
decoded_sentence += letter
return decoded_sentence

sentence = “vhfinmxkl atox kxgwxkxw tee hy maxlx hew vbiaxkl hulhexmx. px’ee atox mh kxteer lmxi ni hnk ztfx by px ptgm mh dxxi hnk fxlltzxl ltyx.”
sentence2 = ‘bqdradyuzs ygxfubxq omqemd oubtqde fa oapq kagd yqeemsqe ue qhqz yadq eqogdq’
offset = 7
offset2 = 14
print(cryptography(sentence, offset))
print(cryptography(sentence2, offset2))

def message(sentence, offset):
coded_sentence = ‘’
for letter in sentence:
if letter.lower() in alphabet:
postion = alphabet[letter]
new_position = (position - offset)
coded_sentence += new_position
else:
coded_sentence += letter
return coded_sentence

sentence = ‘Hola Vishal, como estas?’
offset = 10
print(cryptography(sentence, offset))

def vigenere_decrypt(ciphertext, keyword):

decrypted_message = ''

keyword_repeated = ""
keyword_index = 0

for char in ciphertext:
    if char in alphabet:
        keyword_repeated += keyword[keyword_index % len(keyword)]
        keyword_index += 1
    else:
        keyword_repeated += char


for char, key_char in zip(ciphertext, keyword_repeated):
    if char in alphabet:
        decrypted_char = alphabet[(alphabet.index(char) + alphabet.index(key_char)) % 26]
        decrypted_message += decrypted_char
    else:
        decrypted_message += char

return decrypted_message

Mensaje cifrado y palabra clave

ciphertext = ‘txm srom vkda gl lzlgzr qpdb? fepb ejac! ubr imn tapludwy mhfbz cza ruxzal wg zztylktoikqq!’
keyword = ‘friends’

Descifrar el mensaje

decrypted_message = vigenere_decrypt(ciphertext, keyword)
print(decrypted_message)

def vigenere_crypt(text, keyword):
encrypted_message = ‘’

keyword_repeated = ""
keyword_index = 0

for char in text:
    if char in alphabet:
        keyword_repeated += keyword[keyword_index % len(keyword)]
        keyword_index += 1
    else:
        keyword_repeated += char


for char, key_char in zip(text, keyword_repeated):
    if char in alphabet:
        encrypted_char = alphabet[(alphabet.index(char) - alphabet.index(key_char)) % 26]
        encrypted_message += encrypted_char
    else:
        encrypted_message += char

return encrypted_message

text = ‘hola me llamo xavi’
keyword = ‘astronauta’
encrypted_message = vigenere_crypt(text, keyword)
print(encrypted_message)