Python Forum
Python function that uses a word as the encryption key, rather than an integer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python function that uses a word as the encryption key, rather than an integer
#4
I'm supposed to create a program that uses a word as the encryption key that behaves like this in the end

$ python vigenere.py
Type a message:
The crow flies at midnight!
Encryption key:
boom
Uvs osck rmwse bh auebwsih!
My main issue is with the encrypting aspect of it.

def vigenere_cipher(plaintext, key):
encrypted_string = ''
for i in range(len(key)):
# loop over plaintext by index
    plaintextVal = ord(plaintext)
    # if character in plaintext is alpha do the following:
    keyVal = ord(key[i])
    keyVal = keyVal - 97
    # get alphabet position for character in key

    plaintextChar += chr(keyVal + plaintextVal)
    if plaintextVal >= ord('z')
    #get alphabet position for character in plaintext
        plaintextVal = plaintextVal - 26
        # rotate character from plaintext with a character from the key 
        # convert new position back to a character if you haven't done it already
        # concatenate new character to an encrypted string             


        print PlaintextVal

return encrypted_string
I'm getting a bunch of invalid syntax error throughout and I'm confused on how to go about fixing the code.

Thanks in advanced!
Reply


Messages In This Thread
Encrypting the Vigenere cipher - by wak_stephanie - Aug-31-2018, 03:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,896 Nov-11-2022, 09:03 PM
Last Post: deanhystad
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,509 Aug-12-2021, 04:25 PM
Last Post: palladium
  Question about change hex string to integer sting in the list (python 2.7) lzfneu 1 2,537 May-24-2021, 08:48 AM
Last Post: bowlofred
  need help one time pad encryption implementation ! nad556 1 1,953 Nov-28-2020, 06:11 PM
Last Post: nad556
  encryption and decryption with python ibrahim 1 1,825 May-16-2020, 03:14 PM
Last Post: Larz60+
  Python Speech recognition, word by word AceScottie 6 16,012 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  write an integer to file using a function xvkxvo 4 3,196 Dec-10-2019, 11:27 PM
Last Post: xvkxvo
  File encryption itzik 5 2,883 Nov-05-2019, 12:29 PM
Last Post: Gribouillis
  print a word after specific word search evilcode1 8 4,856 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 2,424 Oct-14-2019, 10:40 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020