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
I'm supposed to create a program that uses a word as the encryption key that behaves like this in the end

$ python
Type a message:
The crow flies at midnight!
Encryption key:
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!

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
  need help one time pad encryption implementation ! nad556 1 202 Nov-28-2020, 06:11 PM
Last Post: nad556
  encryption and decryption with python ibrahim 1 351 May-16-2020, 03:14 PM
Last Post: Larz60+
  Python Speech recognition, word by word AceScottie 6 9,023 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  write an integer to file using a function xvkxvo 4 689 Dec-10-2019, 11:27 PM
Last Post: xvkxvo
  File encryption itzik 5 501 Nov-05-2019, 12:29 PM
Last Post: Gribouillis
  print a word after specific word search evilcode1 8 837 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 636 Oct-14-2019, 10:40 AM
Last Post: perfringo
  A function for correctly using "a/an" before a word Exsul1 2 692 Oct-07-2019, 07:51 PM
Last Post: newbieAuggie2019
  Vernam encryption method for files JohnCTX 1 511 Sep-18-2019, 04:31 PM
Last Post: JohnCTX
  python cache for small integer Uchikago 1 802 Jun-27-2019, 05:32 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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